Java Code Examples for ch.qos.logback.classic.Logger#debug()

The following examples show how to use ch.qos.logback.classic.Logger#debug() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogbackIntegrationTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenParameters_ValuesLogged() {

    Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(LogbackIntegrationTest.class);

    String message = "This is a String";
    Integer zero = 0;

    try {
        logger.debug("Logging message: {}", message);
        logger.debug("Going to divide {} by {}", 42, zero);
        int result = 42 / zero;
    } catch (Exception e) {
        logger.error("Error dividing {} by {} ", 42, zero, e);
    }
}
 
Example 2
Source File: MarkerFilterTest.java    From owasp-security-logging with Apache License 2.0 5 votes vote down vote up
@Test
public void testDecideILoggingEvent() {
	LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

	// create a new marker filter
	MarkerFilter mkt = new MarkerFilter();
	mkt.setContext(lc);
	mkt.setMarker(SecurityMarkers.CONFIDENTIAL_MARKER_NAME);
	mkt.setOnMatch(FilterReply.ACCEPT);
	mkt.setOnMismatch(FilterReply.DENY);
	mkt.start();
	assertTrue(mkt.isStarted());

	// test a logging event with no markers
	ILoggingEvent nulEvent = new LoggingEvent();
	assertEquals(FilterReply.DENY, mkt.decide(nulEvent));

	// test a logging event with the CONFIDENTIAL marker
	LoggingEvent confidentialEvent = new LoggingEvent();
	confidentialEvent.setMarker(SecurityMarkers.CONFIDENTIAL);
	assertEquals(FilterReply.ACCEPT, mkt.decide(confidentialEvent));

	// test a logging event without the CONFIDENTIAL marker
	LoggingEvent normalEvent = new LoggingEvent();
	normalEvent.setMarker(SecurityMarkers.EVENT_SUCCESS);
	assertEquals(FilterReply.DENY, mkt.decide(nulEvent));

	Logger LOGGER = lc.getLogger(MarkerFilterTest.class);
	LOGGER.debug(SecurityMarkers.TOP_SECRET, "You should not see this!");
	LOGGER.debug(SecurityMarkers.CONFIDENTIAL,
			"Look at this confidential information!");
}
 
Example 3
Source File: LogbackIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenConfig_MessageFiltered() {

    Logger foobar = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.foobar");
    Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.logback");
    Logger testslogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.logback.tests");

    foobar.debug("This is logged from foobar");
    logger.debug("This is not logged from logger");
    logger.info("This is logged from logger");
    testslogger.info("This is not logged from tests");
    testslogger.warn("This is logged from tests");


}
 
Example 4
Source File: LogbackIntegrationTest.java    From tutorials with MIT License 4 votes vote down vote up
@Test
public void givenLogHierarchy_MessagesFiltered() {

    ch.qos.logback.classic.Logger parentLogger =
            (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.logback");

    parentLogger.setLevel(Level.INFO);

    Logger childlogger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger("com.baeldung.logback.tests");

    parentLogger.warn("This message is logged because WARN > INFO.");

    // This request is disabled, because DEBUG < INFO.
    parentLogger.debug("This message is not logged because DEBUG < INFO.");

    childlogger.info("INFO == INFO");

    childlogger.debug("DEBUG < INFO");

}