记录器名称,用于使用事件处理程序配置akka记录器

编程入门 行业动态 更新时间:2024-10-27 17:10:32
本文介绍了记录器名称,用于使用事件处理程序配置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记录器

本文发布于:2023-11-15 17:30:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1596513.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:记录器   名称   事件   程序   akka

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!