Search in sources :

Example 26 with Marker

use of org.apache.logging.log4j.Marker in project hive by apache.

the class LlapRoutingAppenderPurgePolicy method update.

@Override
public void update(String key, LogEvent event) {
    Marker marker = event.getMarker();
    if (marker != null && marker.getName() != null && marker.getName().equals(Log4jQueryCompleteMarker.EOF_MARKER)) {
        LOGGER.debug("Received " + Log4jQueryCompleteMarker.EOF_MARKER + " for key. Attempting cleanup.");
        keyComplete(key);
    } else {
        if (knownAppenders.add(key)) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Registered key: [" + key + "] on purgePolicyWithName=" + name + ", thisAddress=" + System.identityHashCode(this));
            }
        }
    }
}
Also used : Marker(org.apache.logging.log4j.Marker)

Example 27 with Marker

use of org.apache.logging.log4j.Marker in project logging-log4j2 by apache.

the class DefaultRouteScriptAppenderTest method logAndCheck.

private void logAndCheck() {
    final Marker marker = MarkerManager.getMarker("HEXDUMP");
    final Logger logger = loggerContextRule.getLogger(DefaultRouteScriptAppenderTest.class);
    logger.error("Hello");
    final ListAppender listAppender = getListAppender();
    final List<LogEvent> list = listAppender.getEvents();
    assertNotNull("No events generated", list);
    assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
    logger.error("World");
    assertTrue("Incorrect number of events. Expected 2, got " + list.size(), list.size() == 2);
    logger.error(marker, "DEADBEEF");
    assertTrue("Incorrect number of events. Expected 3, got " + list.size(), list.size() == 3);
}
Also used : LogEvent(org.apache.logging.log4j.core.LogEvent) ListAppender(org.apache.logging.log4j.test.appender.ListAppender) Marker(org.apache.logging.log4j.Marker) Logger(org.apache.logging.log4j.core.Logger)

Example 28 with Marker

use of org.apache.logging.log4j.Marker in project logging-log4j2 by apache.

the class RoutesScriptAppenderTest method logAndCheck.

private void logAndCheck() {
    final Marker marker = MarkerManager.getMarker("HEXDUMP");
    final Logger logger = loggerContextRule.getLogger(RoutesScriptAppenderTest.class);
    logger.error("Hello");
    final ListAppender listAppender = getListAppender();
    final List<LogEvent> list = listAppender.getEvents();
    assertNotNull("No events generated", list);
    assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
    logger.error("World");
    assertTrue("Incorrect number of events. Expected 2, got " + list.size(), list.size() == 2);
    logger.error(marker, "DEADBEEF");
    assertTrue("Incorrect number of events. Expected 3, got " + list.size(), list.size() == 3);
}
Also used : LogEvent(org.apache.logging.log4j.core.LogEvent) ListAppender(org.apache.logging.log4j.test.appender.ListAppender) Marker(org.apache.logging.log4j.Marker) Logger(org.apache.logging.log4j.core.Logger)

Example 29 with Marker

use of org.apache.logging.log4j.Marker in project logging-log4j2 by apache.

the class PatternLayoutComparisonBenchmark method createLog4j2Event.

private static LogEvent createLog4j2Event() {
    final Marker marker = null;
    final String fqcn = "com.mycom.myproject.mypackage.MyClass";
    final Level level = Level.DEBUG;
    final Message message = new SimpleMessage(STR);
    final Throwable t = null;
    final Map<String, String> mdc = null;
    final ContextStack ndc = null;
    final String threadName = null;
    final StackTraceElement location = null;
    final long timestamp = 12345678;
    return //
    Log4jLogEvent.newBuilder().setLoggerName(//
    "name(ignored)").setMarker(//
    marker).setLoggerFqcn(//
    fqcn).setLevel(//
    level).setMessage(//
    message).setThrown(//
    t).setContextMap(//
    mdc).setContextStack(//
    ndc).setThreadName(//
    threadName).setSource(//
    location).setTimeMillis(//
    timestamp).build();
}
Also used : SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Message(org.apache.logging.log4j.message.Message) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) Level(org.apache.logging.log4j.Level) Marker(org.apache.logging.log4j.Marker) ContextStack(org.apache.logging.log4j.ThreadContext.ContextStack)

Example 30 with Marker

use of org.apache.logging.log4j.Marker in project logging-log4j2 by apache.

the class MarkerAttributeConverterTest method testConvert02.

@Test
public void testConvert02() {
    Marker marker = MarkerManager.getMarker("anotherConvert02").setParents(MarkerManager.getMarker("finalConvert03"));
    marker = MarkerManager.getMarker("testConvert02").setParents(marker);
    final String converted = this.converter.convertToDatabaseColumn(marker);
    assertNotNull("The converted value should not be null.", converted);
    assertEquals("The converted value is not correct.", "testConvert02[ anotherConvert02[ finalConvert03 ] ]", converted);
    final Marker reversed = this.converter.convertToEntityAttribute(converted);
    assertNotNull("The reversed value should not be null.", reversed);
    assertEquals("The reversed value is not correct.", "testConvert02", marker.getName());
    final Marker[] parents = marker.getParents();
    assertNotNull("The first parent should not be null.", parents);
    assertNotNull("The first parent should not be null.", parents[0]);
    assertEquals("The first parent is not correct.", "anotherConvert02", parents[0].getName());
    assertNotNull("The second parent should not be null.", parents[0].getParents());
    assertNotNull("The second parent should not be null.", parents[0].getParents()[0]);
    assertEquals("The second parent is not correct.", "finalConvert03", parents[0].getParents()[0].getName());
}
Also used : Marker(org.apache.logging.log4j.Marker) Test(org.junit.Test)

Aggregations

Marker (org.apache.logging.log4j.Marker)50 Test (org.junit.Test)30 Message (org.apache.logging.log4j.message.Message)23 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)22 Level (org.apache.logging.log4j.Level)18 LogEvent (org.apache.logging.log4j.core.LogEvent)16 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)14 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)8 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)6 ReusableMessage (org.apache.logging.log4j.message.ReusableMessage)6 IOException (java.io.IOException)5 ClockFactoryTest (org.apache.logging.log4j.core.util.ClockFactoryTest)5 ReusableObjectMessage (org.apache.logging.log4j.message.ReusableObjectMessage)5 MutableThreadContextStack (org.apache.logging.log4j.spi.MutableThreadContextStack)5 StringMap (org.apache.logging.log4j.util.StringMap)5 ThreadContext (org.apache.logging.log4j.ThreadContext)4 Logger (org.apache.logging.log4j.core.Logger)4 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)4 HashMap (java.util.HashMap)3 ThrowableProxy (org.apache.logging.log4j.core.impl.ThrowableProxy)3