scala – Akka SLF4J logback配置和用法
发布时间:2020-12-16 09:44:23 所属栏目:安全 来源:网络整理
导读:我已经完成了以下步骤,为我的akka??应用程序尝试配置日志记录: 创建一个application.conf文件并将其放在src / main / resources中。看起来像: akka { event-handlers = ["akka.event.slf4j.Slf4jEventHandler"] loglevel = "INFO" } 创建一个logback.xml
我已经完成了以下步骤,为我的akka??应用程序尝试配置日志记录:
>创建一个application.conf文件并将其放在src / main / resources中。看起来像: akka { event-handlers = ["akka.event.slf4j.Slf4jEventHandler"] loglevel = "INFO" } >创建一个logback.xml文件并将其放在src / main / resources中。看起来像: <configuration> <appender name="FILE" class="ch.qos.logback.core.fileappender"> <File>./logs/akka.log</File> <encoder> <pattern>%d{HH:mm:ss.SSS} [%-5level] %msg%n</pattern> </encoder> </appender> <root level="info"> <appender-ref ref="FILE" /> </root> </configuration> >将以下内容添加到我的.scala sbt构建文件中:
?? import akka.event.Logging 我所得到的只是标准的输出日志记录,没有使用日志创建日志文件。 我错过了一步吗?还是配置错误? 解决方法
有了这个安排,我可以使用akka.event.Logging,不需要指定SLF4J实例。
(2013年12月13日测试) 我得到控制台日志记录和日志文件。 http://doc.akka.io/docs/akka/snapshot/scala/logging.html build.sbt library dependencies: (Akka version 2.2.3) ... "com.typesafe.akka" %% "akka-slf4j" % "2.2.3" "ch.qos.logback" % "logback-classic" % "1.0.9" ... src / main / resources / application.conf akka { loggers = ["akka.event.slf4j.Slf4jLogger"] loglevel = "INFO" } src / main / resources / logback.xml <?xml version="1.0" encoding="UTF-8"?> <configuration> <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> <target>System.out</target> <encoder> <pattern>%X{akkaTimestamp} %-5level[%thread] %logger{0} - %msg%n</pattern> </encoder> </appender> <appender name="FILE" class="ch.qos.logback.core.FileAppender"> <file>log/akka.log</file> <append>false</append> <encoder> <pattern>%date{yyyy-MM-dd} %X{akkaTimestamp} %-5level[%thread] %logger{1} - %msg%n</pattern> </encoder> </appender> <logger name="akka" level="INFO" /> <root level="DEBUG"> <appender-ref ref="CONSOLE"/> <appender-ref ref="FILE"/> </root> </configuration> 当我使用ActorLogging mixin并且还直接创建日志记录时,这种安排是有效的: import akka.event.Logging val log = Logging(context.system,classOf[NameOfYourActor]) log.info("good luck!") (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- WebService学习总结(三)——使用JDK开发WebService
- ELK操作手册----安装elasticssearch
- Bash Node.js stdin / stdout重定向:错误“不是tty”
- 在Bootstrap 3中使用twitter-bootstrap – col – * – 12(
- YUM部署高版本LNMP环境
- Bootstrap的类(CSS和布局组件)的总结
- Scala – 模式匹配相关类型的元组
- angularjs – Angular ui-select error:404(无法加载模板)
- webservices创建和引用
- angularjs – Kendo UI和angular – $scope中没有小部件