问题
How do I make Akka aware of Play's logback config (application-logger.xml)?
In my case it is completely ignored:
The log is ONLY printed to stdout. I expect it to be logged to the File-Appender defined in application-logger.xml
It does not make a difference if I rename application-logger.xml to logback.xml.
Actor-class:
class Dispatcher extends Actor with ActorLogging {
// prints to stdout ONLY:
log.error("[akka-logger] dispatch started...")
}
conf/application.conf:
play {
akka {
#log-config-on-start = on
loggers = ["akka.event.slf4j.Slf4jLogger"]
event-handlers = ["akka.event.slf4j.Slf4jEventHandler"]
loglevel = DEBUG
# and so on...
}
conf/application-logger.xml
<configuration>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${application.home}/logs/application.log</file>
<encoder>
<pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</ pattern>
</encoder>
</appender>
<!-- Using akka.event.slf4j.EventHandler does NOT make a difference here: -->
<logger name="akka.event.slf4j.Slf4jLogger" level="ERROR" additivity="false">
<appender-ref ref="FILE"/>
</logger>
<logger name="play" level="ERROR" additivity="false">
<appender-ref ref="FILE"/>
</logger>
<logger name="application" level="ERROR" additivity="false">
<appender-ref ref="FILE"/>
</logger>
<root level="ERROR">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
</root>
</configuration>
回答1:
I had the same problem. I'm using play 2.2.1 (also tested with 2.2.2) and upgraded version of akka 2.2.3 (But it also works with the version that comes with play). I should also note that I'm using Java not Scala. Here is what I did.
application.conf:
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "DEBUG"
}
And in my logger.xml looks like this:
<configuration>
<conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>${application.home}/logs/applicationmax.log</file>
<encoder>
<pattern>%date ---- [%level] -- %X{akkaSource} -- from %logger in %thread %n%message%n%xException%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%coloredLevel %logger{15} - %message%n%xException{5}</pattern>
</encoder>
</appender>
<logger name="play" level="DEBUG" />
<logger name="application" level="DEBUG" />
<!-- use the package names of classes for specific loggers -->
<logger name="actor" level="DEBUG" />
<root level="ERROR">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>
</configuration>
The key thing to note is that I use the root package name where the actors are as my logger. You can be as specific as you like ie com.actors or com.actors.someactors etc...
You can see more on this google group thread in the play-framework group:
Make Akka aware of Play's logback configuration
回答2:
The default file name used by play for logback is logger.xml
- see reference.
You may also want to change the root level from error to debug to make sure you get any log messages at all at root level.
来源:https://stackoverflow.com/questions/16048087/make-akka-aware-of-plays-logback-configuration