[英]Using loggers in a static context in Akka actors
我正在使用Akka推荐的事件日志记录来自演员的日志:
public class MyActor extends AbstractActor {
private final LoggingAdapter logger = Logging.getLogger(getContext().getSystem(), this);
@Override
public Receive createReceive() {
// do stuff here
logger.log("Did Stuff here");
}).matchAny(unhandled -> unhandled(unhandled)).build();
}
public static helperMethodForActorTodoItsJob() {
// Can't log here because of the static context?
}
}
我了解为什么建议在actor中使用事件日志记录,但是如何登录静态方法? 我应该创建另一个记录器吗? 它如何影响性能? 还是演员中不应该有静态方法? 这里的最佳做法是什么?
通常,您可以做的是将通过log()
方法(即,如果您选择扩展AbstractLoggingActor
)获得的LoggingAdapter
传递为类方法的参数。 如果这是你想要做什么取决于你为什么会想它是在第一时间和/或什么方法做静态的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.