Akka.actor.ActorLogging Does Not Log Exception Stack Trace Using Logback Protocol

I use Logback + SLF4J for journaling for those actors with the akka.actor.ActorLogging . However, when I do the log.error("Error occur!", e) code, the trace of the exception stack e not logged, but only the line Error occur! WARNING arguments left: 1 Error occur! WARNING arguments left: 1 . I wonder why and how to print the stack trace in the log file. Thanks. The following is the configuration of the logback.groovy file.

 appender("FILE", RollingFileAppender) { file = "./logs/logd.txt" append = true rollingPolicy(TimeBasedRollingPolicy) { fileNamePattern = "./logs/logd.%d{yyyy-MM-dd}.log" maxHistory = 30 } encoder(PatternLayoutEncoder) { pattern = "%date{ISO8601} [%thread] %-5level %logger{36} %X{sourceThread} - %msg%n" } } root(DEBUG, ["FILE"]) 
+6
source share
2 answers

Akka has a separate registration, which is configured in the Akka application.conf application. If you want to connect to SLF4J / Logback - use these settings:

 akka { loggers = ["akka.event.slf4j.Slf4jLogger"] loglevel = "DEBUG" } 

See: http://doc.akka.io/docs/akka/2.0/scala/logging.html

As far as I can see here , the reason (Throwable) should be the first argument to log.error :

  def error(cause: Throwable, message: String) 

That's why you see โ€œWARNING Arguments Remainedโ€ - your Throwable argument was simply ignored.

+15
source

The exception of the reason should be the first argument of error , and not the second (as correctly pointed out by JasonG in the comment to another answer).

Using Akka's logging system instead of 'bare' scala -logging has some advantages with respect to automatically added metadata and easier testing / filtering.

See also:

0
source

Source: https://habr.com/ru/post/975632/


All Articles