Java ClassicConstants-class And Method Code Example
Here is an example of how you can use the ClassicConstants class from the logback.classic package:
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.util.ClassicConstants;
import org.slf4j.LoggerFactory;
public class MyClass {
public static void main(String[] args) {
// Get the logger
Logger logger = (Logger) LoggerFactory.getLogger(MyClass.class);
// Get the logger context
LoggerContext context = logger.getLoggerContext();
// Set the root logger level using the ClassicConstants class
context.getLogger(ClassicConstants.ROOT_LOGGER_NAME).setLevel(Level.ERROR);
// Set the logger level using the ClassicConstants class
logger.setLevel(Level.DEBUG);
}
}
The ClassicConstants
class is a utility class that provides constants used in the logback.classic package. In this example, we use the ROOT_LOGGER_NAME constant to set the root logger level and the DEBUG constant to set the logger level.
The ROOT_LOGGER_NAME
constant is a string representing the name of the root logger, which is "ROOT". The DEBUG constant is an instance of the Level class representing the debug log level.