Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set log level for scala-logging

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?

like image 817
Kombajn zbożowy Avatar asked Mar 11 '17 23:03

Kombajn zbożowy


People also ask

How do you change the log level?

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.

How do you define logging level?

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.

What is the best logging level?

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.


2 Answers

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.

like image 80
Andrei T. Avatar answered Sep 28 '22 07:09

Andrei T.


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)
like image 32
Kombajn zbożowy Avatar answered Sep 28 '22 08:09

Kombajn zbożowy