Friday 25 February 2022

Logback: Print internal state information

Below snippet prints the internal state of logback library.

LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
StatusPrinter.print(loggerContext);

 

Find the below working application.

 

PrintInternalState.java

 

package com.sample.app;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.util.StatusPrinter;

public class PrintInternalState {

	public static void main(String[] args) {

		Logger logger = LoggerFactory.getLogger(PrintInternalState.class);
		logger.debug("Hello world....");

		// print internal state
		LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
		StatusPrinter.print(loggerContext);
	}
}

 

Output

19:46:45.837 [main] DEBUG com.sample.app.PrintInternalState - Hello world....
19:46:45,798 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
19:46:45,799 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.xml]
19:46:45,801 |-INFO in ch.qos.logback.classic.BasicConfigurator@7e6cbb7a - Setting up default configuration.

 

From the outptut, you can confirm that Logback library is failed to find the logback-test.xml and logback.xml configuration files, and it is configured itself using its default policy.

 


 

Previous                                                 Next                                                 Home

No comments:

Post a Comment