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?
相关问题
- Unusual use of the new keyword
- Get Runtime Type picked by implicit evidence
- What's the point of nonfinal singleton objects
- I want to trace logs using a Macro multi parameter
- PlayFramework: how to transform each element of a
相关文章
- Gatling拓展插件开发,check(bodyString.saveAs("key"))怎么实现
- how do I log requests and responses for debugging
- RDF libraries for Scala [closed]
- Why is my Dispatching on Actors scaled down in Akk
- How do you run cucumber with Scala 2.11 and sbt 0.
- GRPC: make high-throughput client in Java/Scala
- Android Studio doesn't display logs by package
- Setting up multiple test folders in a SBT project
simply create your own logger:
I've now settled on simply passing my central logging system around through DI constructor injection (Guice). And in my classes that do logging regularly (where asynchronicity is important), I take the injected ActorSystem and call the
in the classes constructor.
Actually I would redirect Akka logging to slf4j and use this API directly in all unrelated classes. First add this to your configuration:
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:
The
%X{akkaSource}
will print actor path when available (just like standard logging).Using Akka 2.2.1, I was able to put this into my App to get logging outside of an actor:
This seems like a simpler solution for unifying an application's logging.
As has been mentioned, you're spoiled for options for non-actor logging within an actor system. I am going to attempt to provide a set of heuristics to help you determine how you should route logging for your work.
You're welcome to mix and match the above behaviors as necessary to meet your requirements. For example, you might choose to bind to SLF4J for libraries and use Akka logging for everything else. Just note that mixing blocking and non-blocking logging could cause race conditions where causes (logged async via an actor) are logged after their effects (logged sync directly).