use of org.apache.logging.log4j.core.LogEvent in project logging-log4j2 by apache.
the class ReusableLogEventFactoryTest method testCreateEventInitFieldsProperly.
@SuppressWarnings("deprecation")
@Test
public void testCreateEventInitFieldsProperly() throws Exception {
final ReusableLogEventFactory factory = new ReusableLogEventFactory();
final LogEvent event = callCreateEvent(factory, "logger", Level.INFO, new SimpleMessage("xyz"), null);
ReusableLogEventFactory.release(event);
assertNotNull(event.getContextMap());
assertNotNull(event.getContextData());
assertNotNull(event.getContextStack());
}
use of org.apache.logging.log4j.core.LogEvent in project cas by apereo.
the class CasAppender method append.
@Override
public void append(final LogEvent logEvent) {
final LogEvent newLogEvent = LoggingUtils.prepareLogEvent(logEvent);
final String refName = this.appenderRef.getRef();
if (StringUtils.isNotBlank(refName)) {
final Appender appender = this.config.getAppender(refName);
if (appender != null) {
appender.append(newLogEvent);
} else {
LOGGER.warn("No log appender could be found for [{}]", refName);
}
} else {
LOGGER.warn("No log appender reference could be located in logging configuration.");
}
}
use of org.apache.logging.log4j.core.LogEvent in project cas by apereo.
the class LoggingUtils method prepareLogEvent.
/**
* Prepare log event log event.
*
* @param logEvent the log event
* @return the log event
*/
public static LogEvent prepareLogEvent(final LogEvent logEvent) {
final String messageModified = TicketIdSanitizationUtils.sanitize(logEvent.getMessage().getFormattedMessage());
final Message message = new SimpleMessage(messageModified);
final LogEvent newLogEvent = Log4jLogEvent.newBuilder().setLevel(logEvent.getLevel()).setLoggerName(logEvent.getLoggerName()).setLoggerFqcn(logEvent.getLoggerFqcn()).setContextMap(logEvent.getContextMap()).setContextStack(logEvent.getContextStack()).setEndOfBatch(logEvent.isEndOfBatch()).setIncludeLocation(logEvent.isIncludeLocation()).setMarker(logEvent.getMarker()).setMessage(message).setNanoTime(logEvent.getNanoTime()).setSource(logEvent.getSource()).setThreadName(logEvent.getThreadName()).setThrownProxy(logEvent.getThrownProxy()).setThrown(logEvent.getThrown()).setTimeMillis(logEvent.getTimeMillis()).build();
return newLogEvent;
}
use of org.apache.logging.log4j.core.LogEvent in project camel by apache.
the class BaseNettyTest method verifyNoLeaks.
@AfterClass
public static void verifyNoLeaks() throws Exception {
//Force GC to bring up leaks
System.gc();
//Kick leak detection logging
ByteBufAllocator.DEFAULT.buffer(1).release();
Collection<LogEvent> events = LogCaptureAppender.getEvents();
if (!events.isEmpty()) {
String message = "Leaks detected while running tests: " + events;
// Just write the message into log to help debug
for (LogEvent event : events) {
LOG.info(event.getMessage().getFormattedMessage());
}
LogCaptureAppender.reset();
throw new AssertionError(message);
}
}
use of org.apache.logging.log4j.core.LogEvent in project graylog2-server by Graylog2.
the class MemoryAppenderTest method appenderCanConsumeMoreMessagesThanBufferSize.
@Test
public void appenderCanConsumeMoreMessagesThanBufferSize() {
final int bufferSize = 10;
final MemoryAppender appender = MemoryAppender.createAppender(null, null, "memory", String.valueOf(bufferSize), "false");
assertThat(appender).isNotNull();
for (int i = 1; i <= bufferSize + 1; i++) {
final LogEvent logEvent = Log4jLogEvent.newBuilder().setLevel(Level.INFO).setLoggerName("test").setLoggerFqcn("com.example.test").setMessage(new SimpleMessage("Message " + i)).build();
appender.append(logEvent);
}
final List<LogEvent> messages = appender.getLogMessages(bufferSize);
for (int i = 0; i < messages.size(); i++) {
assertThat(messages.get(i).getMessage().getFormattedMessage()).isEqualTo("Message " + (bufferSize - i + 1));
}
}
Aggregations