简体   繁体   中英

How can I add silencable logging to my sbt Scala project?

I'm new at logging and I've got a println for debugging that I would like to be able to silence.

I tried Scala Logging with Logback ( runnable example ), but I'm surprised that I can't silence the new logger by changing the sbt log level, eg > warn .

Can sbt control another logger's log levels?

Or should I be trying to use sbt's logger instead?

Logback has its own configuration file to control the logging in the application. You need a "logback.xml" to be in src/main/resources folder to configure. The below is a simple example, you could control your log at any levels , the below case will not print out debug level logs. In addtion, you can set up complexed loggings such as file based logging and more. See http://logback.qos.ch/manual/configuration.html for detail

<configuration>
  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}: %msg%n</pattern>
    </encoder>
  </appender>
  <root level="info">
    <appender-ref ref="CONSOLE" />
  </root>
</configuration>

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