我曾尝试使用log4j和slf4j与scala中的akka,我能够获取日志文件。如果不使用akka API以外的任何外部API,我可以实现相同的功能吗?通过使用akka.event.Logging我可以在控制台中打印日志,但我想将其打印在文件中。我们可以使用akka.event.Logging在文件中写入日志吗?
我已经尝试在classpath中为我的项目设置log4j.properties文件,并且在我使用akka.event.Logging时它不工作。
请建议。
我曾尝试使用log4j和slf4j与scala中的akka,我能够获取日志文件。如果不使用akka API以外的任何外部API,我可以实现相同的功能吗?通过使用akka.event.Logging我可以在控制台中打印日志,但我想将其打印在文件中。我们可以使用akka.event.Logging在文件中写入日志吗?
我已经尝试在classpath中为我的项目设置log4j.properties文件,并且在我使用akka.event.Logging时它不工作。
请建议。
因此这个http://doc.akka.io/docs/akka/current/java/logging.html 你有3种选择:
akka.event.Logging$DefaultLogger
(到stdout,而不是用于生产)akka.event.slf4j.Slf4jLogger
(由阿卡的SLF4J记录器)您的情况是2或3(您使用log4j.properties
)。 因此,您应该正确配置文件log4j.properties
以便在文件中输出。 而
akka.event.Logging
,例如:Logging.getLogger(system.eventStream(), “my.string”)org.slf4j.LoggerFactory.getLogger(...)
你的情况是2,如果您在阿卡的配置是这样的使用方法:
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
loglevel = "DEBUG"
logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
}
这个配置做?我做了你提到的以下配置,但我仍然无法获取日志文件。 log4j.rootLogger = INFO,文件 log4j.appender.file = org.apache.log4j.DailyRollingFileAppender log4j.appender.file.layout = org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern = [%d] [%p] [%c {1}] [%t] - %m%n log4j.appender.file.file ='。'yyyy-MM-dd log4j.appender.file.file = D:\\ scalalogfile.log –
我能看到我的控制台中的日志,但没有创建日志文件。 –
它现在正在工作,但我在logback.xml中配置了.... log4j.properties不起作用。 –
你有没有配置阿卡accordingl? http://doc.akka.io/docs/akka/current/java/logging.html – rethab
是的,我根据这个配置doc.akka.io/docs/akka/current/scala/logging.html –