演员外的Akka记录 [英] Akka Logging outside Actor
问题描述
我有一个Akka演员打给MyObject.foo()
. MyObject
不是演员.如何设置登录?使用Actor很简单,因为我可以混入ActorLogging.在MyObject中,我无权访问context.system.是否要使用AkkaSystem()创建akka.event.Logging
,然后隐式创建LogSource呢?
I have an Akka Actor that makes a call to MyObject.foo()
. MyObject
is not an Actor. How do I setup Logging in it? With an Actor it's simple, because I can just mixin ActorLogging. In MyObject, I don't have access to context.system. Do I create an akka.event.Logging
with AkkaSystem() and then what for the LogSource implicit?
推荐答案
实际上,我会将Akka日志重定向到 slf4j 并直接在所有不相关的类中使用此API.首先,将其添加到您的配置中:
Actually I would redirect Akka logging to slf4j and use this API directly in all unrelated classes. First add this to your configuration:
akka {
event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
loglevel = "DEBUG"
}
然后选择一些SLF4J实现,我建议logback .在您的演员中继续使用ActorLogging
特征.在其他类中,仅依赖于SLF4J API-甚至更好-可以尝试围绕SLF4J的 slf4s 外观.
Then choose some SLF4J implementation, I suggest logback. In your actors continue using ActorLogging
trait. In other classes simply rely on SLF4J API - or even better - try out slf4s facade around SLF4J.
提示:在Logback中尝试以下记录模式:
Tip: try out the following logging pattern in Logback:
<pattern>%d{HH:mm:ss.SSS} | %-5level | %thread | %X{akkaSource} | %logger{1} | %m%n%rEx</pattern>
%X{akkaSource}
将在可用时打印actor路径(就像标准日志记录一样).
The %X{akkaSource}
will print actor path when available (just like standard logging).
这篇关于演员外的Akka记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!