Search in sources :

Example 6 with Log4jLogEvent

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") };
}
Also used : MutableThreadContextStack(org.apache.logging.log4j.spi.MutableThreadContextStack) ThreadContextStack(org.apache.logging.log4j.spi.ThreadContextStack) StringMapMessage(org.apache.logging.log4j.message.StringMapMessage) StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) KeyValuePair(org.apache.logging.log4j.core.util.KeyValuePair) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) MutableThreadContextStack(org.apache.logging.log4j.spi.MutableThreadContextStack) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 7 with Log4jLogEvent

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()));
        }
    }
}
Also used : ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Message(org.apache.logging.log4j.message.Message) HashMap(java.util.HashMap) Logger(org.apache.logging.log4j.Logger) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) File(java.io.File) Test(org.junit.Test)

Example 8 with Log4jLogEvent

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;
}
Also used : Serializable(java.io.Serializable) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 9 with Log4jLogEvent

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;
}
Also used : Serializable(java.io.Serializable) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) Benchmark(org.openjdk.jmh.annotations.Benchmark)

Example 10 with Log4jLogEvent

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);
}
Also used : Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) AbstractJacksonLayout(org.apache.logging.log4j.jackson.AbstractJacksonLayout)

Aggregations

Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)37 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)15 Test (org.junit.Test)15 AbstractJacksonLayout (org.apache.logging.log4j.jackson.AbstractJacksonLayout)14 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 MutableLogEvent (org.apache.logging.log4j.core.impl.MutableLogEvent)5 Log4jJsonObjectMapper (org.apache.logging.log4j.jackson.json.Log4jJsonObjectMapper)5 KeyValuePair (org.apache.logging.log4j.core.util.KeyValuePair)4 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)4 StringMap (org.apache.logging.log4j.util.StringMap)4 Serializable (java.io.Serializable)3 ThrowableProxy (org.apache.logging.log4j.core.impl.ThrowableProxy)3 Message (org.apache.logging.log4j.message.Message)3 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)3 Test (org.junit.jupiter.api.Test)3 Benchmark (org.openjdk.jmh.annotations.Benchmark)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Marker (org.apache.logging.log4j.Marker)2 Log4jJsonObjectMapper (org.apache.logging.log4j.core.jackson.Log4jJsonObjectMapper)2