简体   繁体   中英

How to set SLF4J logging appenders for akka ActorSystem's logger

I am initializing an ActorSystem using

implicit val system: ActorSystem = ActorSystem("my-system", config)

and want to be use the FileAppender and ConsoleAppender s I use for logging in my application.

I currently have this following in my reference.conf to use the slf4j logger but I believe I need to set my appenders to the logger to get the logs to be grouped with my other application logs.

akka {

  # Loggers to register at boot time (akka.event.Logging$DefaultLogger logs
  # to STDOUT)
  loggers = ["akka.event.slf4j.Slf4jLogger"]

  # Log level used by the configured loggers (see "loggers") as soon
  # as they have been started; before that, see "stdout-loglevel"
  # Options: OFF, ERROR, WARNING, INFO, DEBUG
  loglevel = "DEBUG"

  # Log level for the very basic logger activated during ActorSystem startup.
  # This logger prints the log messages to stdout (System.out).
  # Options: OFF, ERROR, WARNING, INFO, DEBUG
  stdout-loglevel = "DEBUG"

  # Filter of log events that is used by the LoggingAdapter before
  # publishing log events to the eventStream.
  logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"

  use-slf4j = on
}

Try this in logback.xml ?

    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>logs/application.log</file>
        <encoder>
            <pattern>%date [%level] from %logger in %thread - %.-65535msg%n%xException</pattern>
        </encoder>
    </appender>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM