use of org.apache.logging.log4j.core.impl.Log4jLogEvent in project logging-log4j2 by apache.
the class MapRewritePolicyTest method setupClass.
@BeforeAll
public static void setupClass() {
stringMap.putValue("test1", "one");
stringMap.putValue("test2", "two");
map = stringMap.toMap();
logEvent0 = //
Log4jLogEvent.newBuilder().setLoggerName(//
"test").setContextData(//
stringMap).setLoggerFqcn(//
"MapRewritePolicyTest.setupClass()").setLevel(//
Level.ERROR).setMessage(//
new SimpleMessage("Test")).setThrown(//
new RuntimeException("test")).setThreadName("none").setSource(new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 28)).setTimeMillis(2).build();
logEvent1 = //
((Log4jLogEvent) logEvent0).asBuilder().setMessage(//
new StringMapMessage(map)).setSource(//
new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 29)).build();
final ThreadContextStack stack = new MutableThreadContextStack(new ArrayList<>(map.values()));
logEvent2 = //
((Log4jLogEvent) logEvent0).asBuilder().setContextStack(//
stack).setMarker(//
MarkerManager.getMarker("test")).setLevel(//
Level.TRACE).setMessage(//
new StructuredDataMessage("test", "Nothing", "test", map)).setTimeMillis(//
20000000).setSource(//
new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 30)).build();
logEvent3 = //
((Log4jLogEvent) logEvent0).asBuilder().setContextStack(//
stack).setLevel(//
Level.ALL).setMessage(//
new StringMapMessage(map)).setTimeMillis(//
Long.MAX_VALUE).setSource(//
new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 31)).build();
rewrite = new KeyValuePair[] { new KeyValuePair("test2", "2"), new KeyValuePair("test3", "three") };
}
use of org.apache.logging.log4j.core.impl.Log4jLogEvent in project logging-log4j2 by apache.
the class AsyncLoggerConfigTest3 method testNoConcurrentModificationException.
@Test
public void testNoConcurrentModificationException() throws Exception {
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, "AsyncLoggerConfigTest2.xml");
final File file = new File("target", "AsyncLoggerConfigTest2.log");
assertTrue("Deleted old file before test", !file.exists() || file.delete());
final Logger log = LogManager.getLogger("com.foo.Bar");
log.info("initial message");
Thread.sleep(500);
final Map<String, String> map = new HashMap<>();
for (int j = 0; j < 3000; j++) {
map.put(String.valueOf(j), String.valueOf(System.nanoTime()));
}
final Message msg = new ParameterizedMessage("{}", map);
Log4jLogEvent event = Log4jLogEvent.newBuilder().setLevel(Level.WARN).setLoggerName(getClass().getName()).setMessage(msg).setTimeMillis(0).build();
for (int i = 0; i < 100; i++) {
((AsyncLoggerConfig) ((org.apache.logging.log4j.core.Logger) log).get()).callAppenders(event);
for (int j = 0; j < 3000; j++) {
map.remove(String.valueOf(j));
}
for (int j = 0; j < 3000; j++) {
map.put(String.valueOf(j), String.valueOf(System.nanoTime()));
}
}
}
use of org.apache.logging.log4j.core.impl.Log4jLogEvent in project logging-log4j2 by apache.
the class Log4jLogEventBenchmark method createSerializableLogEventProxyWithoutException.
@Benchmark
public Serializable createSerializableLogEventProxyWithoutException(final Blackhole bh) {
final Log4jLogEvent event = new Log4jLogEvent("a.b.c", null, "a.b.c", Level.INFO, MESSAGE, null, null);
final Serializable obj = Log4jLogEvent.serialize(event, false);
bh.consume(obj);
return obj;
}
use of org.apache.logging.log4j.core.impl.Log4jLogEvent in project logging-log4j2 by apache.
the class Log4jLogEventBenchmark method createSerializableLogEventProxyWithException.
@Benchmark
public Serializable createSerializableLogEventProxyWithException(final Blackhole bh) {
final Log4jLogEvent event = new Log4jLogEvent("a.b.c", null, "a.b.c", Level.INFO, MESSAGE, null, ERROR);
final Serializable obj = Log4jLogEvent.serialize(event, false);
bh.consume(obj);
return obj;
}
use of org.apache.logging.log4j.core.impl.Log4jLogEvent in project logging-log4j2 by apache.
the class JsonLayoutTest method prepareJsonForStacktraceTests.
private String prepareJsonForStacktraceTests(final boolean stacktraceAsString) {
final Log4jLogEvent expected = LogEventFixtures.createLogEvent();
// @formatter:off
final AbstractJacksonLayout layout = JsonLayout.newBuilder().setCompact(true).setIncludeStacktrace(true).setStacktraceAsString(stacktraceAsString).build();
// @formatter:off
return layout.toSerializable(expected);
}
Aggregations