记录器名称,用于使用事件处理程序配置akka记录器 [英] logger names for configuring akka logger using the event-handler

查看:67
本文介绍了记录器名称,用于使用事件处理程序配置akka记录器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用 Slf4jEventHandler 和经典的logback.如何分别为不同参与者配置日志级别? [我正在使用Akka 2.0_M2]

So, I am using Slf4jEventHandler and logback-classic. How do I configure the log levels for different actors separately? [I am using Akka 2.0_M2]

我尝试做类似

<configuration debug="true" scan="true">
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <pattern>%-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    <logger name="akka://TradeService" level="DEBUG" />
    <root level="INFO">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>

但这根本没有帮助:

INFO  akka://TradeService/user/realTimeReqListener - Declaring queue
INFO  akka://TradeService/user/restReqListener - Declaring queue
INFO  akka://TradeService/user/restReqListener - Starting listening to queue

如您所见,我仅获得有关演员的INFO级别日志记录.角色记录器的命名层次是什么?

As you can see I am only getting INFO level logging for the actors. What is the naming hierarchy for actor loggers?

推荐答案

我猜您正在使用Akka 2.0里程碑,并且我进一步猜想您是这样获得记录器的:

I am guessing that you are using an Akka 2.0 milestone, and I am further guessing that you obtain your logger like this:

val log = Logging(context.system, this)

如前所述,就日志类别而言,角色的默认表示形式是其路径.不幸的是,logback尚未准备好处理actor层次结构,而是将其设置为处理包名称(即点分隔的层次结构),这就是为什么您的设置会影响错误的记录器的原因. Akka master最近在此区域进行了一些更改,这些更改将成为里程碑3(现在将很快发布)的一部分,该里程碑将从实际的实现类中获取默认日志类别(根据LoggerFactory.getLogger(someClass)).如果您想在旧版本的Akka上实现相同的目标,请使用

As documented, the default representation of an actor in terms of log category is its path. Unfortunately, logback is not prepared to deal with actor hierarchies, it is setup to deal with package names (i.e. dot-separated hierarchy), which is why your setting affects the wrong logger. There were some changes in this area in Akka master recently which will be part of milestone 3 (to be released real soon now), where the default log category would be obtained from the actual implementation class (as per LoggerFactory.getLogger(someClass)). If you want to achieve the same thing on your older Akka version, use

val log = Logging(context.system, getClass.getName)

请注意,这当然不会使您的程序包名称神奇地统一actor名称层次结构,即,您将必须按照传统Java日志记录框架的惯例为每个actor类进行配置.如果需要的话,编写自己的从角色路径到点分隔的层次结构名称的转换,并将结果字符串传递给工厂:

Note that this of course does NOT unify the actor name hierarchy magically with your package names, i.e. you will have to configure per actor class as is customary for traditional Java logging frameworks. If you want that, write your own conversion from actor path to dot-separated hierarchical name and pass the resulting string to the factory:

val log = Logging(context.system.eventStream, mangleMyName(self.path))

一旦您更新到较新的版本,就必须更改为使用eventStream而不是普通的system,因为另一个更改是,如果传入系统,则系统名称现在将追加到普通日志记录类别中.假设system.name == "Fred":

The change to using eventStream instead of plain system will be necessary once you update to a more recent version, because another change was that the system’s name will now be appended to plain logging categories if passing in a system. Assume system.name == "Fred":

val log = Logging(context.system, "testa") // will log as "testa(Fred)"

这篇关于记录器名称,用于使用事件处理程序配置akka记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆