This library is useful for simulating Log Levels in SLF4J 2.0.x. There is no such implementation by default.
(If you still need old SLF4J 1.x implementation, it is available as version 1.2.1.)
Visit the GitHub Pages site for more.
<dependency>
<groupId>com.ocarlsen.logging</groupId>
<artifactId>slf4j-log-level</artifactId>
<version>2.0.1-SNAPSHOT</version>
</dependency>
compile 'com.ocarlsen.logging:slf4j-log-level:2.0.1-SNAPSHOT'
Consider the class with an SLF4J Logger:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
class MyLoggingClass {
private static final Logger LOGGER = LoggerFactory.getLogger(MyLoggingClass.class);
}
To get the LogLevel of a Logger programmatically, use the static get
method like this:
LogLevel logLevel = LogLevel.get(LOGGER);
To log events at a certain LogLevel without using the specific method name (e.g. without using debug
explicitly), you
can choose the appropriate instance from the LogLevel
enum and simply call log
like this:
LogLevel.DEBUG.log(LOGGER, "this is a debug message");
The logging methods taking format arguments are implemented:
LogLevel.INFO.log(LOGGER, "int {}, boolean {}, enum {}", 123, true, DayOfWeek.MONDAY);
As are the methods taking Throwable
:
LogLevel.WARN.log(LOGGER, "somthing went wrong", new IllegalArgumentException("oops"))
These examples and more are demonstrated in the unit tests ( e.g. LogLevelDebugTest) and LogLevelTestManual .