I am implementing a distributed database with scala 2.9 and akka 2.0. My current problem is I want to redirect the standard logging to a file instead of stdout. I don’t realy want to use SLF4J or SLF4S. Is there a simple way to redirect the logging output?
Share
The akka documentation for logging says, that you can register handlers in the config like this:
There is also an SLF4J handler
Using this you can add any SLF4J compliant library like logback to write your logs to wherever you want.
edit:
To use logback to log to a file you have to add logback as a dependency, add the Slf4jEventHandler to your config:
and add a logback config to your project that lokks something like this (taken from logback docs):
Due to the async logging in akka you cannot use the %thread variable in your log pattern, instead use the
sourceThreadvariable from the MDC. You can read about that at the bottom of this page: http://doc.akka.io/docs/akka/2.0/scala/logging.htmlYou don’t have to explicitly use slf4j or logback in your code, just use the normal akka logging, the handler will take care of everything else.