use of org.apache.logging.log4j.spi.ExtendedLogger in project logging-log4j2 by apache.
the class TestLoggerContext method getLogger.
@Override
public ExtendedLogger getLogger(final String name) {
final ExtendedLogger extendedLogger = map.get(name);
if (extendedLogger != null) {
return extendedLogger;
}
final ExtendedLogger logger = new TestLogger(name);
map.put(name, logger);
return logger;
}
use of org.apache.logging.log4j.spi.ExtendedLogger in project logging-log4j2 by apache.
the class Category method maybeLog.
void maybeLog(final String fqcn, final org.apache.logging.log4j.Level level, final Object message, final Throwable throwable) {
if (logger.isEnabled(level)) {
final Message msg;
if (message instanceof String) {
msg = new SimpleMessage((String) message);
} else // SimpleMessage treats String and CharSequence differently, hence this else-if block.
if (message instanceof CharSequence) {
msg = new SimpleMessage((CharSequence) message);
} else if (message instanceof Map) {
@SuppressWarnings("unchecked") final Map<String, ?> map = (Map<String, ?>) message;
msg = new MapMessage<>(map);
} else {
msg = new ObjectMessage(message);
}
if (logger instanceof ExtendedLogger) {
((ExtendedLogger) logger).logMessage(fqcn, level, null, msg, throwable);
} else {
logger.log(level, msg, throwable);
}
}
}
use of org.apache.logging.log4j.spi.ExtendedLogger in project logging-log4j2 by apache.
the class Log4j2Jira1688Test method testLog4j2Only.
@Test
public void testLog4j2Only() throws InterruptedException {
final org.apache.logging.log4j.Logger log4JLogger = LogManager.getLogger(this.getClass());
// more than unrolled varargs
final int limit = 11;
final Object[] args = createArray(limit);
final Object[] originalArgs = Arrays.copyOf(args, args.length);
listAppender.countDownLatch = new CountDownLatch(1);
((ExtendedLogger) log4JLogger).logIfEnabled("test", Level.ERROR, null, "test {}", args);
listAppender.countDownLatch.await(1, TimeUnit.SECONDS);
Assert.assertArrayEquals(Arrays.toString(args), originalArgs, args);
((ExtendedLogger) log4JLogger).logIfEnabled("test", Level.ERROR, null, "test {}", args);
Assert.assertArrayEquals(Arrays.toString(args), originalArgs, args);
}
use of org.apache.logging.log4j.spi.ExtendedLogger in project logging-log4j2 by apache.
the class AsyncAppenderTest method testNoLocationInformation.
@Test
@LoggerContextSource("log4j-asynch-no-location.xml")
public void testNoLocationInformation(final LoggerContext context, @Named("List") final ListAppender appender) throws InterruptedException {
final ExtendedLogger logger = context.getLogger(getClass());
logger.error("This is a test");
logger.warn("Hello world!");
final List<String> messages;
try {
messages = appender.getMessages(2, 2, TimeUnit.SECONDS);
} finally {
appender.clear();
}
assertNotNull(messages);
assertEquals(2, messages.size());
assertEquals("? This is a test", messages.get(0));
assertEquals("? Hello world!", messages.get(1));
}
use of org.apache.logging.log4j.spi.ExtendedLogger in project pinpoint by naver.
the class Log4j2Binder method getLogger.
@Override
public PLogger getLogger(String name) {
final PLogger hitPLogger = loggerCache.get(name);
if (hitPLogger != null) {
return hitPLogger;
}
ExtendedLogger logger = loggerContext.getLogger(name);
PLogger log4j2Adapter = new Log4j2PLoggerAdapter(logger);
final PLogger before = loggerCache.putIfAbsent(name, log4j2Adapter);
if (before != null) {
return before;
}
return log4j2Adapter;
}
Aggregations