darecoder
darecoder

Reputation: 1608

Can we use akka.event.Logging to write logs in file?

I have tried using log4j and slf4j with akka in scala and I am able to get log files. Can I achieve the same thing without using any external api other than akka APIs? By using akka.event.Logging I am able to print logs in console, but I want to print it in a file.

I have already tried setting log4j.properties file for my project in classpath and its not working when I am using akka.event.Logging.

Please suggest.

Upvotes: 0

Views: 1168

Answers (1)

Dedkov Vadim
Dedkov Vadim

Reputation: 436

Accordingly to this http://doc.akka.io/docs/akka/current/java/logging.html you have 3 options:

  1. Use akka.event.Logging$DefaultLogger (to stdout, not for production)
  2. Use akka.event.slf4j.Slf4jLogger (logger by akka for SLF4J)
  3. Use the SLF4J API directly (with async appender)

Your case is 2 or 3 (you use log4j.properties). Therefore you should properly configure file log4j.properties for output in file. And

  • in case 2 (your desired case), you should use akka.event.Logging, for example: Logging.getLogger(system.eventStream(), "my.string")
  • in case 3, you should use SLF4J API, for example: org.slf4j.LoggerFactory.getLogger(...)

Your case is 2, if you use in your akka config something like this:

akka {
  loggers = ["akka.event.slf4j.Slf4jLogger"]
  loglevel = "DEBUG"
  logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
}

Upvotes: 1

Related Questions