use of org.apache.logging.log4j.spi.AbstractLogger in project logging-log4j2 by apache.
the class LoggerAwareTagSupportTest method testGetLoggerWithTaglibLogger.
@Test
public void testGetLoggerWithTaglibLogger() throws Exception {
this.setUp(null);
final AbstractLogger wrapped = (AbstractLogger) LogManager.getLogger("testGetLoggerWithTaglibLogger");
final Log4jTaglibLogger logger = new Log4jTaglibLogger(wrapped, wrapped.getName(), wrapped.getMessageFactory());
this.tag.setLogger(logger);
Log4jTaglibLogger returned = this.tag.getLogger();
assertNotNull("The first returned logger should not be null.", returned);
assertSame("The first returned logger should be the same as the set.", logger, returned);
assertEquals("The name is not correct.", "testGetLoggerWithTaglibLogger", returned.getName());
returned = this.tag.getLogger();
assertNotNull("The second returned logger should not be null.", returned);
assertSame("The second returned logger should be the same as the set.", logger, returned);
}
use of org.apache.logging.log4j.spi.AbstractLogger in project logging-log4j2 by apache.
the class TagUtils method resolveLogger.
static Log4jTaglibLogger resolveLogger(final Log4jTaglibLoggerContext context, final Object logger, final MessageFactory factory) throws JspException {
if (logger instanceof Logger) {
if (logger instanceof Log4jTaglibLogger) {
return (Log4jTaglibLogger) logger;
}
if (logger instanceof AbstractLogger) {
if (LOGGER.isInfoEnabled() && !WARNED_FOR.contains(logger)) {
LOGGER.info("Constructing new Log4jTaglibLogger from AbstractLogger {} name and message factory.", logger.getClass().getName());
WARNED_FOR.add(logger);
}
final AbstractLogger original = (AbstractLogger) logger;
return getLogger(context, original.getName(), original.getMessageFactory());
}
throw new JspException("Log4j Tag Library requires base logging system to extend Log4j AbstractLogger.");
}
if (logger instanceof String) {
return getLogger(context, (String) logger, factory);
}
throw new JspException("Logger must be of type String or org.apache.logging.log4j.Logger.");
}
use of org.apache.logging.log4j.spi.AbstractLogger in project logging-log4j2 by apache.
the class AsyncLoggerConfigUseAfterShutdownTest method testNoErrorIfLogAfterShutdown.
@Test
public void testNoErrorIfLogAfterShutdown() throws Exception {
final Logger log = LogManager.getLogger("com.foo.Bar");
log.info("some message");
// stop async thread
CoreLoggerContexts.stopLoggerContext();
// call the #logMessage() method to bypass the isEnabled check:
// before the LOG4J2-639 fix this would throw a NPE
((AbstractLogger) log).logMessage("com.foo.Bar", Level.INFO, null, new SimpleMessage("msg"), null);
}
use of org.apache.logging.log4j.spi.AbstractLogger in project logging-log4j2 by apache.
the class AsyncLoggerEventTranslationExceptionTest method testEventTranslationExceptionDoesNotCauseAsyncEventException.
@Test
void testEventTranslationExceptionDoesNotCauseAsyncEventException() {
final Logger log = LogManager.getLogger("com.foo.Bar");
assertTrue(TestExceptionHandler.INSTANTIATED, "TestExceptionHandler was not configured properly");
final Message exceptionThrowingMessage = new ExceptionThrowingMessage();
assertThrows(TestMessageException.class, () -> ((AbstractLogger) log).logMessage("com.foo.Bar", Level.INFO, null, exceptionThrowingMessage, null));
// stop async thread
CoreLoggerContexts.stopLoggerContext();
assertFalse(TestExceptionHandler.EVENT_EXCEPTION_ENCOUNTERED, "ExceptionHandler encountered an event exception");
}
use of org.apache.logging.log4j.spi.AbstractLogger in project logging-log4j2 by apache.
the class AsyncLoggerUseAfterShutdownTest method testNoErrorIfLogAfterShutdown.
@Test
public void testNoErrorIfLogAfterShutdown() throws Exception {
final Logger log = LogManager.getLogger("com.foo.Bar");
final String msg = "Async logger msg";
log.info(msg, new InternalError("this is not a real error"));
// stop async thread
CoreLoggerContexts.stopLoggerContext();
// call the #logMessage() method to bypass the isEnabled check:
// before the LOG4J2-639 fix this would throw a NPE
((AbstractLogger) log).logMessage("com.foo.Bar", Level.INFO, null, new SimpleMessage("msg"), null);
}
Aggregations