演员外的Akka记录 [英] Akka Logging outside Actor

查看:81
本文介绍了演员外的Akka记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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日志重定向到

.在您的演员中继续使用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屋!

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