Akka Logging outside Actor

后端 未结 6 1477
孤街浪徒
孤街浪徒 2021-01-30 09:02

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

6条回答
  •  灰色年华
    2021-01-30 09:18

    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"
    }
    

    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.

    Tip: try out the following logging pattern in Logback:

    %d{HH:mm:ss.SSS} | %-5level | %thread | %X{akkaSource} | %logger{1} | %m%n%rEx
    

    The %X{akkaSource} will print actor path when available (just like standard logging).

提交回复
热议问题