My console app takes a log-level=<LEVEL>
option. Looking at some examples in Java , it looks like changing SLF4J logger level is generally possible, but with scala-logging library it seems like this is not the case - regardless of how I create the logger it doesn't have setLevel
method available. Any suggestions?
The library needs a logging backend (you can check out the prerequisites). Once you define it, you can set the logging level via a configuration file, for example:
// src/main/resources/logback.xml
<configuration>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"/>
<root level="debug">
<appender-ref ref="stdout"/>
</root>
</configuration>
This will result in setting the log level to DEBUG
for that particular logger. Anyway, this should work if you're using the slf4j backend. I hope this helps you.
Based on this answer I used this piece of code and it did the work for me:
import ch.qos.logback.classic.{Level,Logger}
import org.slf4j.LoggerFactory
LoggerFactory
.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME)
.asInstanceOf[Logger]
.setLevel(Level.INFO)
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.