Log names for configuring akka logger with an event handler

So, I am using Slf4jEventHandler and logback-classic. How to set log levels for different participants separately? [I am using Akka 2.0_M2]

I tried to do something like

<configuration debug="true" scan="true"> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>%-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <logger name="akka://TradeService" level="DEBUG" /> <root level="INFO"> <appender-ref ref="STDOUT" /> </root> </configuration> 

but it did not help:

 INFO akka://TradeService/user/realTimeReqListener - Declaring queue INFO akka://TradeService/user/restReqListener - Declaring queue INFO akka://TradeService/user/restReqListener - Starting listening to queue 

As you can see, I only get INFO level registration for actors. What is the naming hierarchy for data loggers?

+6
source share
2 answers

I assume that you are using the Akka 2.0 milestone, and I also assume that you get your registrar as follows:

 val log = Logging(context.system, this) 

As indicated, the standard representation of an actor in terms of the category of a magazine is its path. Unfortunately, logback is not ready to work with actor hierarchies, it is configured to handle package names (i.e. separated by hierarchy points), so your parameter affects the wrong registrar. Recently, there have been some changes in this area in the Akka workshop, which will be part of milestone 3 (coming soon), where the default journal category will be derived from the actual implementation class (according to LoggerFactory.getLogger(someClass) ). If you want to achieve the same result in your old version of Akka, use

 val log = Logging(context.system, getClass.getName) 

Please note that it is NOT NECESSARY to combine the actor name hierarchy with the names of your packages, i.e. you will have to set up a class for each actor, as is usually the case with traditional Java frameworks. If you want this, write your own conversion from the actor’s path to a hierarchical name, separated by a dot, and pass the resulting string to the factory:

 val log = Logging(context.system.eventStream, mangleMyName(self.path)) 

A change when using eventStream instead of a simple system will be necessary after you upgrade to a later version, since another change was that the system name will now be added to the simple categories of logging while going through the system. Suppose system.name == "Fred" :

 val log = Logging(context.system, "testa") // will log as "testa(Fred)" 
+6
source

Akka Logging does not integrate very well with Play out of the box. It also uses a different API for slf4j, for example. warning instead of warning, making replacement difficult if you need to.

The symptom below leads to the classic slf4j / log4j package name structure, which simplifies the configuration of registrars in application.conf

 import org.slf4j.LoggerFactory import akka.actor.ActorRef trait ActorLogger { implicit val self:ActorRef protected val log = LoggerFactory.getLogger(getClass().getName() + "_" + self.path.toString()) } 

and use it like this:

 class Foo extends Actor with ActorLogger { def run = { log.info("hi") log.warn("hi") } } 
+1
source

All Articles