【问题标题】:Route Restlet logging to log4j2路由 Restlet 日志到 log4j2
【发布时间】:2015-03-11 08:16:49
【问题描述】:

我想将 restlet 日志记录桥接到 log4j2,以便正确记录 LogServices。目前,我的日志模式中有完全限定的类名,例如:[org.restlet.Component.InternalRouter],但 LogService 记录为[.Logservice](这不是所需的行为)。我的类路径中没有 slf4j 桥的类,也不需要它们(slf4j api 类除外)。我使用所有依赖项来桥接 JUL、log4j1.x、Slf4j。

之前使用 slf4j,我使用了 restlet documentation/“JULI 的 SLF4J 桥接器”部分中的代码来桥接输出。使用代码删除处理程序将导致异常,因为不再有处理程序。

我正在使用 log4j2 2.2 和 restlet 2.0.15

【问题讨论】:

    标签: logging restlet log4j2 restlet-2.0


    【解决方案1】:

    Restlet 使用 JDK 的日志记录 API,您可以将其桥接到 log4j。

    如果您愿意,您自己的类可以使用 SLF4J API(不过我更喜欢 logj4 API),它也可以桥接到 log4j。

    在运行时类路径中需要两个桥接器:log4j-jul e log4j-slf4j-impl。

    在 Maven 中,执行:

    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-jul</artifactId>
      <version>2.2</version>
      <scope>runtime</scope>
    </dependency>
    
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
      <version>2.2</version>
      <scope>runtime</scope>
    </dependency>
    

    这样,您可以使用 Log4j 进行配置。

    【讨论】:

    • 我已经使用了 slf4j 和 jul 桥。我还使用System.setProperty("java.util.logging.manager", LogManager.class.getName()) 添加了 JUL 桥。
    • Each component also logs access using a name such as "org.restlet.MyComponent.LogService". This name can be customized using the "LogService.loggerName" property. -- 可能有人将 LogService.loggerName 设置为 .Logservice
    猜你喜欢
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    • 2021-10-17
    • 1970-01-01
    • 2016-10-24
    • 1970-01-01
    • 2020-04-23
    • 1970-01-01
    相关资源
    最近更新 更多