完成"Scala记录"例子 [英] Complete "Scala Logging" Example

查看:91
本文介绍了完成"Scala记录"例子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Typesafe的 Scala日志记录,但无法获取它来打印任何调试消息.我希望Scala Logging可以将调试消息打印到默认屏幕,但是它不起作用.一个完整的示例将非常有帮助,或者具体建议更改内容也将非常有用.我使用Scala 2.11.这是我所做的:

I'm trying to use Typesafe's Scala Logging but couldn't get it to print any debug message. I expect Scala Logging to print debug message to the default screen but it doesn't work. A complete example would be very helpful or specific advise what to change would be great too. I use Scala 2.11. Here is what I did:

  1. 我将依赖项添加到build.sbt:

  1. I added the dependency to build.sbt:

libraryDependencies += "com.typesafe.scala-logging" %% "scala-logging" % "3.1.0"

即使我不确定是否需要这样做,我还是添加了以下行,但没有任何区别:

Even though I'm not sure if this is required, I added the following line but it didn't do any difference:

libraryDependencies += "com.typesafe.scala-logging" % "scala-logging-slf4j_2.11" % "2.1.2"

  • 这是我班级的基本样子:

  • This is how my class looks like basically:

    import com.typesafe.scalalogging._
    
    class MyClass extends LazyLogging {
      // ...
      logger.debug("Here goes my debug message.")
      // ...
    }
    

  • 我发现了文件./src/main/resources/logback.xml,但不确定是哪个模块安装的,以及是否相关.我将日志级别更改为调试",没有任何效果.

  • I discovered the file ./src/main/resources/logback.xml but am not sure which module installed it and if its relevant. I changed the log level to "debug" without effect.

    <configuration>
    
      <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type
             ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
          <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
      </appender>
    
      <logger name="scala.slick" level="DEBUG"/>
    
      <root level="debug">
        <appender-ref ref="STDOUT" />
      </root>
    </configuration>
    

  • 推荐答案

    IIRC,它将默认打印从信息级别开始的消息.要更改此设置,您需要将logback.xml文件放入src/main/resources(或使用-Dlogback.configurationFile=/path/to/config.xml JVM参数).请参阅Logback文档中的配置一章.

    IIRC it'll print messages starting from info level by default. To change this, you need to put logback.xml file into src/main/resources (or use -Dlogback.configurationFile=/path/to/config.xml JVM parameter). See Configuration chapter in Logback documentation.

    这篇关于完成"Scala记录"例子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆