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?
Server Configuration File You can change the log level through a Windows Registry file or a Linux configuration file. Add the logLevel string, and set the desired value (e.g., DEBUG). Click OK to save.
What Is a Logging Level. A log level or log severity is a piece of information telling how important a given log message is. It is a simple, yet very powerful way of distinguishing log events from each other. If the log levels are used properly in your application all you need is to look at the severity first.
Some of them are important, others less important, while others are meta-considerations. The standard ranking of logging levels is as follows: ALL < TRACE < DEBUG < INFO < WARN < ERROR < FATAL < OFF.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With