簡體   English   中英

在Akka actor中的靜態上下文中使用記錄器

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM