Java 类org.apache.logging.log4j.MarkerManager 实例源码

项目:elasticsearch_my    文件:PrefixLogger.java   
PrefixLogger(final ExtendedLogger logger, final String name, final String prefix) {
    super(logger, name, null);

    final String actualPrefix = (prefix == null ? "" : prefix).intern();
    final Marker actualMarker;
    // markers is not thread-safe, so we synchronize access
    synchronized (markers) {
        final WeakReference<Marker> marker = markers.get(actualPrefix);
        final Marker maybeMarker = marker == null ? null : marker.get();
        if (maybeMarker == null) {
            actualMarker = new MarkerManager.Log4jMarker(actualPrefix);
            markers.put(actualPrefix, new WeakReference<>(actualMarker));
        } else {
            actualMarker = maybeMarker;
        }
    }
    this.marker = actualMarker;
}
项目:es-log4j2-appender    文件:ElasticSearchRestAppenderTest.java   
/**
 * Integration test that asserts events are sent to the Elastic cluster in bulk.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void integrationTestAfter5() throws IOException {
    String test = "integration-test-after-5";
    Logger logger = getLogger(test);
    ElasticClient client = new ElasticClient(logger);
    String marker = getUniqueMarker();

    // Should not send until it reaches 5 events
    for (int i = 1; i < 5; i++) {
        logger.error(MarkerManager.getMarker(marker), i + "-" + test);
    }
    JsonNode doc = client.findFirstByMarker(marker);
    assertNull(doc);

    // But after the 5th event it should send all buffered events
    logger.error(MarkerManager.getMarker(marker), "5-" + test);
    JsonNode hits = client.findAllByMarker(marker);
    assertNotNull(hits);
    assertEquals(5, hits.size());
    for (int i = 0; i < 5; i++) {
        assertFieldValue(hits.get(i).get("_source"), "level", "ERROR");
        assertFieldValue(hits.get(i).get("_source"), "message", (i + 1) + "-" + test);
    }
}
项目:graylog-plugin-internal-logs    文件:SerializedLogEventCodecTest.java   
private LogEvent createLogEvent(DateTime timestamp) {
    final MutableLogEvent logEvent = new MutableLogEvent();

    logEvent.setMessage(new SimpleMessage("Test"));
    logEvent.setLevel(Level.TRACE);
    logEvent.setLoggerName("org.example.Test");
    logEvent.setMarker(MarkerManager.getMarker("TestMarker"));
    logEvent.setTimeMillis(timestamp.getMillis());
    logEvent.setNanoTime(42L);

    logEvent.setContextStack(new MutableThreadContextStack(ImmutableList.of("one", "two")));
    final SortedArrayStringMap contextData = new SortedArrayStringMap(1);
    contextData.putValue("foobar", "quux");
    logEvent.setContextData(contextData);

    logEvent.setThreadId(23L);
    logEvent.setThreadName("thread-name");
    logEvent.setThreadPriority(42);

    logEvent.setThrown(new Throwable("Test", new Throwable("cause")));

    logEvent.setIncludeLocation(true);

    return logEvent.createMemento();
}
项目:log4j2    文件:PatternParserTest.java   
/**
 * Test the custom pattern
 */
@Test
public void testCustomPattern() {
    final List<PatternFormatter> formatters = parser.parse(customPattern);
    assertNotNull(formatters);
    final Map<String, String> mdc = new HashMap<String, String>();
    mdc.put("loginId", "Fred");
    final Throwable t = new Throwable();
    final StackTraceElement[] elements = t.getStackTrace();
    final LogEvent event = new Log4jLogEvent("org.apache.logging.log4j.PatternParserTest", MarkerManager.getMarker("TEST"),
        Logger.class.getName(), Level.INFO, new SimpleMessage("Hello, world"), null,
        mdc, null, "Thread1", elements[0], System.currentTimeMillis());
    final StringBuilder buf = new StringBuilder();
    for (final PatternFormatter formatter : formatters) {
        formatter.format(event, buf);
    }
    final String str = buf.toString();
    final String expected = "INFO  [PatternParserTest        :96  ] - Hello, world" + Constants.LINE_SEP;
    assertTrue("Expected to end with: " + expected + ". Actual: " + str, str.endsWith(expected));
}
项目:log4j2    文件:PatternParserTest.java   
@Test
public void testNestedPattern() {
    final List<PatternFormatter> formatters = parser.parse(nestedPattern);
    assertNotNull(formatters);
    final Throwable t = new Throwable();
    final StackTraceElement[] elements = t.getStackTrace();
    final LogEvent event = new Log4jLogEvent("org.apache.logging.log4j.PatternParserTest", MarkerManager.getMarker("TEST"),
            Logger.class.getName(), Level.INFO, new SimpleMessage("Hello, world"), null, null, null, "Thread1", elements[0],
            System.currentTimeMillis());
    final StringBuilder buf = new StringBuilder();
    for (final PatternFormatter formatter : formatters) {
        formatter.format(event, buf);
    }
    final String str = buf.toString();
    final String expected = String.format("] INFO : Hello, world%s\u001B[m", Constants.LINE_SEP);
    assertTrue(" Expected to end with: " + expected + ". Actual: " + str, str.endsWith(expected));
}
项目:log4j2    文件:MarkerAttributeConverterTest.java   
@Test
public void testConvert02() {
    final Marker marker = MarkerManager.getMarker("testConvert02",
            MarkerManager.getMarker("anotherConvert02",
                    MarkerManager.getMarker("finalConvert03")
            )
    );

    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());
    assertNotNull("The first parent should not be null.", marker.getParent());
    assertEquals("The first parent is not correct.", "anotherConvert02", marker.getParent().getName());
    assertNotNull("The second parent should not be null.", marker.getParent().getParent());
    assertEquals("The second parent is not correct.", "finalConvert03", marker.getParent().getParent().getName());
}
项目:Fishification    文件:FishWorld.java   
private void initXlsLogger() {
    try {

        // Prepare application string
        String applicationVersion = getConfiguration().getString("application.version", "0.0.1");
        applicationVersion += "." + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());

        // Init Logger
        File outputDirectory = new File(s_xlsLoggerOutputPath);
        m_xlsLogger = new XlsLogger(outputDirectory, s_xlsLoggerOutputFileName, s_xlsLoggerInitialSheetName,
                                    applicationVersion);
    } catch (Exception e) {
        m_log.error(MarkerManager.getMarker("EXCEPTION"), "Error while opening XLS logger.", e);
        m_xlsLogger = null;
    }
}
项目:Fishification    文件:ContentLoader.java   
public ContentLoader(String baseUrl, int basePort, String restEndpoint, FishWorld fishWorld) {
    m_fishWorld = fishWorld;

    // Initialize CommunityMashup
    ConnectionManager.init(baseUrl, basePort, restEndpoint);

    // Initialize ContentCollector
    m_contentCollector = new ContentCollectRunnable();

    // Begin data collection after short delay
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(START_SLEEP);
            } catch (InterruptedException e) {
                m_log.warn(MarkerManager.getMarker("EXCEPTION"), "BeginDataCollection sleep interrupted.");
            }
            beginDataCollection();
        }
    }).start();

}
项目:logstash-gelf    文件:GelfLogAppenderMinimalTests.java   
@Test
public void testSimpleInfo() throws Exception {

    Logger logger = loggerContext.getLogger(getClass().getName());

    logger.info(new MarkerManager.Log4jMarker("test"), LOG_MESSAGE);
    assertThat(GelfTestSender.getMessages()).hasSize(1);

    GelfMessage gelfMessage = GelfTestSender.getMessages().get(0);
    assertThat(gelfMessage.getFullMessage()).isEqualTo(EXPECTED_LOG_MESSAGE);
    assertThat(gelfMessage.getShortMessage()).isEqualTo(EXPECTED_LOG_MESSAGE);
    assertThat(gelfMessage.getField("MyTime")).isNotNull();
    assertThat(gelfMessage.getAdditonalFields().get("Marker")).isEqualTo("test");
    assertThat(gelfMessage.getLevel()).isEqualTo("6");

    assertThat(gelfMessage.getField(LogMessageField.NamedLogField.SourceLineNumber.name())).isNotNull();
    assertThat(gelfMessage.getField(LogMessageField.NamedLogField.SourceMethodName.name())).isEqualTo("testSimpleInfo");
    assertThat(gelfMessage.getField(LogMessageField.NamedLogField.SourceClassName.name())).isEqualTo(getClass().getName());

}
项目:logging-log4j2    文件:Log4jMarkerFactory.java   
private static org.apache.logging.log4j.Marker convertMarker(final Marker original,
                                                             final Collection<Marker> visited) {
    final org.apache.logging.log4j.Marker marker = MarkerManager.getMarker(original.getName());
    if (original.hasReferences()) {
        final Iterator<Marker> it = original.iterator();
        while (it.hasNext()) {
            final Marker next = it.next();
            if (visited.contains(next)) {
                LOGGER.warn("Found a cycle in Marker [{}]. Cycle will be broken.", next.getName());
            } else {
                visited.add(next);
                marker.addParents(convertMarker(next, visited));
            }
        }
    }
    return marker;
}
项目:logging-log4j2    文件:MarkerTest.java   
@Test
public void testAddMarker() {
    final String childMakerName = CHILD_MAKER_NAME + "-AM";
    final String parentMarkerName = PARENT_MARKER_NAME + "-AM";
    final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMakerName);
    final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMarkerName);
    slf4jMarker.add(slf4jParent);
    final Marker log4jParent = MarkerManager.getMarker(parentMarkerName);
    final Marker log4jMarker = MarkerManager.getMarker(childMakerName);

    assertTrue("Incorrect Marker class", slf4jMarker instanceof Log4jMarker);
    assertTrue(String.format("%s (log4jMarker=%s) is not an instance of %s (log4jParent=%s) in Log4j",
            childMakerName, parentMarkerName, log4jMarker, log4jParent), log4jMarker.isInstanceOf(log4jParent));
    assertTrue(String.format("%s (slf4jMarker=%s) is not an instance of %s (log4jParent=%s) in SLF4J",
            childMakerName, parentMarkerName, slf4jMarker, slf4jParent), slf4jMarker.contains(slf4jParent));
}
项目:logging-log4j2    文件:MarkerTest.java   
@Test
public void testEquals() {
    final String childMarkerName = CHILD_MAKER_NAME + "-ASM";
    final String parentMakerName = PARENT_MARKER_NAME + "-ASM";
    final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker(childMarkerName);
    final org.slf4j.Marker slf4jMarker2 = org.slf4j.MarkerFactory.getMarker(childMarkerName);
    final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker(parentMakerName);
    slf4jMarker.add(slf4jParent);
    final Marker log4jParent = MarkerManager.getMarker(parentMakerName);
    final Marker log4jMarker = MarkerManager.getMarker(childMarkerName);
    final Marker log4jMarker2 = MarkerManager.getMarker(childMarkerName);
    assertEquals(log4jParent, log4jParent);
    assertEquals(log4jMarker, log4jMarker);
    assertEquals(log4jMarker, log4jMarker2);
    assertEquals(slf4jMarker, slf4jMarker2);
    assertNotEquals(log4jParent, log4jMarker);
    assertNotEquals(log4jMarker, log4jParent);
}
项目:logging-log4j2    文件:MarkerAttributeConverterTest.java   
@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());
}
项目:logging-log4j2    文件:PatternParserTest.java   
private void testNestedPatternHighlight(final Level level, final String expectedStart) {
    final List<PatternFormatter> formatters = parser.parse(nestedPatternHighlight);
    assertNotNull(formatters);
    final Throwable t = new Throwable();
    t.getStackTrace();
    final LogEvent event = Log4jLogEvent.newBuilder() //
            .setLoggerName("org.apache.logging.log4j.PatternParserTest") //
            .setMarker(MarkerManager.getMarker("TEST")) //
            .setLoggerFqcn(Logger.class.getName()) //
            .setLevel(level) //
            .setMessage(new SimpleMessage("Hello, world")) //
            .setThreadName("Thread1") //
            .setSource(/*stackTraceElement[0]*/ null) //
            .setTimeMillis(System.currentTimeMillis()) //
            .build();
    final StringBuilder buf = new StringBuilder();
    for (final PatternFormatter formatter : formatters) {
        formatter.format(event, buf);
    }
    final String str = buf.toString();
    final String expectedEnd = String.format("] %-5s: Hello, world%s\u001B[m", level, Strings.LINE_SEPARATOR);
    assertTrue("Expected to start with: " + expectedStart + ". Actual: " + str, str.startsWith(expectedStart));
    assertTrue("Expected to end with: \"" + expectedEnd + "\". Actual: \"" + str, str.endsWith(expectedEnd));
}
项目:logging-log4j2    文件:PatternSelectorTest.java   
@Test
public void testPatternSelector() throws Exception {
    final PatternMatch[] patterns = new PatternMatch[1];
    patterns[0] = new PatternMatch("FLOW", "%d %-5p [%t]: ====== %C{1}.%M:%L %m ======%n");
    final PatternSelector selector = MarkerPatternSelector.createSelector(patterns, "%d %-5p [%t]: %m%n", true, true, ctx.getConfiguration());
    final PatternLayout layout = PatternLayout.newBuilder().withPatternSelector(selector)
            .withConfiguration(ctx.getConfiguration()).build();
    final LogEvent event1 = Log4jLogEvent.newBuilder() //
            .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.layout.PatternSelectorTest$FauxLogger")
            .setMarker(MarkerManager.getMarker("FLOW"))
            .setLevel(Level.TRACE) //
            .setIncludeLocation(true)
            .setMessage(new SimpleMessage("entry")).build();
    final String result1 = new FauxLogger().formatEvent(event1, layout);
    final String expectSuffix1 = String.format("====== PatternSelectorTest.testPatternSelector:53 entry ======%n");
    assertTrue("Unexpected result: " + result1, result1.endsWith(expectSuffix1));
    final LogEvent event2 = Log4jLogEvent.newBuilder() //
            .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
            .setLevel(Level.INFO) //
            .setMessage(new SimpleMessage("Hello, world 1!")).build();
    final String result2 = new String(layout.toByteArray(event2));
    final String expectSuffix2 = String.format("Hello, world 1!%n");
    assertTrue("Unexpected result: " + result2, result2.endsWith(expectSuffix2));
}
项目:logging-log4j2    文件:PatternLayoutTest.java   
@Test
public void testEqualsEmptyMarker() throws Exception {
    // replace "[]" with the empty string
    final PatternLayout layout = PatternLayout.newBuilder().withPattern("[%logger]%equals{[%marker]}{[]}{} %msg")
            .withConfiguration(ctx.getConfiguration()).build();
    // Not empty marker
    final LogEvent event1 = Log4jLogEvent.newBuilder() //
            .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
            .setLevel(Level.INFO) //
            .setMarker(MarkerManager.getMarker("TestMarker")) //
            .setMessage(new SimpleMessage("Hello, world!")).build();
    assertToByteArray("[org.apache.logging.log4j.core.layout.PatternLayoutTest][TestMarker] Hello, world!", layout,
            event1);
    assertEncode("[org.apache.logging.log4j.core.layout.PatternLayoutTest][TestMarker] Hello, world!", layout,
            event1);
    // empty marker
    final LogEvent event2 = Log4jLogEvent.newBuilder() //
            .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
            .setLevel(Level.INFO) //
            .setMessage(new SimpleMessage("Hello, world!")).build();
    assertToByteArray("[org.apache.logging.log4j.core.layout.PatternLayoutTest] Hello, world!", layout, event2);
    assertEncode("[org.apache.logging.log4j.core.layout.PatternLayoutTest] Hello, world!", layout, event2);
}
项目:logging-log4j2    文件:PatternLayoutTest.java   
@Test
public void testPatternSelector() throws Exception {
    final PatternMatch[] patterns = new PatternMatch[1];
    patterns[0] = new PatternMatch("FLOW", "%d %-5p [%t]: ====== %C{1}.%M:%L %m ======%n");
    final PatternSelector selector = MarkerPatternSelector.createSelector(patterns, "%d %-5p [%t]: %m%n", true, true, ctx.getConfiguration());
    final PatternLayout layout = PatternLayout.newBuilder().withPatternSelector(selector)
            .withConfiguration(ctx.getConfiguration()).build();
    final LogEvent event1 = Log4jLogEvent.newBuilder() //
            .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.layout.PatternLayoutTest$FauxLogger")
            .setMarker(MarkerManager.getMarker("FLOW"))
            .setLevel(Level.TRACE) //
            .setIncludeLocation(true)
            .setMessage(new SimpleMessage("entry")).build();
    final String result1 = new FauxLogger().formatEvent(event1, layout);
    final String expectPattern1 = String.format(".*====== PatternLayoutTest.testPatternSelector:\\d+ entry ======%n");
    assertTrue("Unexpected result: " + result1, result1.matches(expectPattern1));
    final LogEvent event2 = Log4jLogEvent.newBuilder() //
            .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
            .setLevel(Level.INFO) //
            .setMessage(new SimpleMessage("Hello, world 1!")).build();
    final String result2 = new String(layout.toByteArray(event2));
    final String expectSuffix2 = String.format("Hello, world 1!%n");
    assertTrue("Unexpected result: " + result2, result2.endsWith(expectSuffix2));
}
项目:logging-log4j2    文件:PatternLayoutTest.java   
@Test
public void testRegexEmptyMarker() throws Exception {
    // replace "[]" with the empty string
    final PatternLayout layout = PatternLayout.newBuilder().withPattern("[%logger]%replace{[%marker]}{\\[\\]}{} %msg")
            .withConfiguration(ctx.getConfiguration()).build();
    // Not empty marker
    final LogEvent event1 = Log4jLogEvent.newBuilder() //
            .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
            .setLevel(Level.INFO) //
            .setMarker(MarkerManager.getMarker("TestMarker")) //
            .setMessage(new SimpleMessage("Hello, world!")).build();
    assertToByteArray("[org.apache.logging.log4j.core.layout.PatternLayoutTest][TestMarker] Hello, world!", layout,
            event1);
    assertEncode("[org.apache.logging.log4j.core.layout.PatternLayoutTest][TestMarker] Hello, world!", layout,
            event1);

    // empty marker
    final LogEvent event2 = Log4jLogEvent.newBuilder() //
            .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
            .setLevel(Level.INFO) //
            .setMessage(new SimpleMessage("Hello, world!")).build();
    assertToByteArray("[org.apache.logging.log4j.core.layout.PatternLayoutTest] Hello, world!", layout, event2);
    assertEncode("[org.apache.logging.log4j.core.layout.PatternLayoutTest] Hello, world!", layout, event2);
}
项目:logging-log4j2    文件:PatternLayoutTest.java   
@Test
public void testEqualsMarkerWithMessageSubstitution() throws Exception {
    // replace "[]" with the empty string
    final PatternLayout layout = PatternLayout.newBuilder().withPattern("[%logger]%equals{[%marker]}{[]}{[%msg]}")
        .withConfiguration(ctx.getConfiguration()).build();
    // Not empty marker
    final LogEvent event1 = Log4jLogEvent.newBuilder() //
        .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
        .setLevel(Level.INFO) //
        .setMarker(MarkerManager.getMarker("TestMarker"))
        .setMessage(new SimpleMessage("Hello, world!")).build();
    final byte[] result1 = layout.toByteArray(event1);
    assertEquals("[org.apache.logging.log4j.core.layout.PatternLayoutTest][TestMarker]", new String(result1));
    // empty marker
    final LogEvent event2 = Log4jLogEvent.newBuilder() //
        .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
        .setLevel(Level.INFO)
        .setMessage(new SimpleMessage("Hello, world!")).build();
    final byte[] result2 = layout.toByteArray(event2);
    assertEquals("[org.apache.logging.log4j.core.layout.PatternLayoutTest][Hello, world!]", new String(result2));
}
项目:es-log4j2-appender    文件:ElasticSearchRestAppenderTest.java   
/**
 * Integration test that asserts events are sent to the Elastic cluster.
 *
 * @throws IOException Signals that an I/O exception has occurred.
 */
@Test
public void integrationTest() throws IOException {
    String test = "integration-test";
    Logger logger = getLogger(test);
    ElasticClient client = new ElasticClient(logger);
    String marker = getUniqueMarker();
    logger.error(MarkerManager.getMarker(marker), "Test Message");
    JsonNode doc = client.findFirstByMarker(marker);
    assertNotNull(doc);
    assertFieldValue(doc, "level", "ERROR");
    assertFieldValue(doc, "message", "Test Message");
}
项目:monarch    文件:FastLoggerIntegrationJUnitTest.java   
@Before
public void setUp() throws Exception {
  System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
  this.configFile = new File(this.temporaryFolder.getRoot(), "log4j2-test.xml");
  this.configFileLocation = this.configFile.toURI().toURL().toString();
  this.enabledMarker = MarkerManager.getMarker(ENABLED_MARKER_NAME);
  this.unusedMarker = MarkerManager.getMarker(UNUSED_MARKER_NAME);
  setUpLogService();
}
项目:clusterbrake    文件:AbstractState.java   
public AbstractState(StateContext context) {
    this.logger = LogManager.getLogger(getClass());
    this.marker = MarkerManager.getMarker("StateMachine");
    this.isActive = new AtomicBoolean();
    this.context = context;
    this.conditionalMap = new HashMap<>();
}
项目:log4j2    文件:LoggingMessageTagSupportTest.java   
@Test
public void testDoEndTagStringMessageMarkerNoException() throws Exception {
    this.setUp(Level.INFO);

    this.tag.setMarker(MarkerManager.getMarker("E01"));
    this.tag.setMessage("Goodbye message for testDoEndTagStringMessageMarkerNoException");

    assertEquals("The return value is not correct.", BodyTag.EVAL_PAGE, this.tag.doEndTag());
    verify("Goodbye message for testDoEndTagStringMessageMarkerNoException INFO M-E01 E");
}
项目:log4j2    文件:LoggingMessageTagSupportTest.java   
@Test
public void testDoEndTagStringMessageMarkerException() throws Exception {
    this.setUp(Level.TRACE);

    this.tag.setException(new RuntimeException("This is another test"));
    this.tag.setMarker(MarkerManager.getMarker("F02"));
    this.tag.setMessage("Final message for testDoEndTagStringMessageMarkerException");

    assertEquals("The return value is not correct.", BodyTag.EVAL_PAGE, this.tag.doEndTag());
    verify("Final message for testDoEndTagStringMessageMarkerException TRACE M-F02 E java.lang.RuntimeException: This is another test");
}
项目:log4j2    文件:LoggingMessageTagSupportTest.java   
@Test
public void testDoEndTagStringWithParametersMarkerAndException() throws Exception {
    this.setUp(Level.DEBUG);

    this.tag.setException(new Error("This is the last test"));
    this.tag.setMarker(MarkerManager.getMarker("N03"));
    this.tag.setDynamicAttribute(null, null, "Z");
    this.tag.setDynamicAttribute(null, null, TimeUnit.SECONDS);
    this.tag.setMessage("Final message with [{}] parameter of [{}]");

    assertEquals("The return value is not correct.", BodyTag.EVAL_PAGE, this.tag.doEndTag());
    verify("Final message with [Z] parameter of [SECONDS] DEBUG M-N03 E java.lang.Error: This is the last test");

}
项目:log4j2    文件:LoggingMessageTagSupportTest.java   
@Test
public void testDoEndTagMessageMarkerNoException() throws Exception {
    this.setUp(Level.WARN);

    this.tag.setMarker(MarkerManager.getMarker("E01"));
    this.tag.setMessage(
            logger.getMessageFactory().newMessage("Another message for testDoEndTagMessageMarkerNoException")
    );

    assertEquals("The return value is not correct.", BodyTag.EVAL_PAGE, this.tag.doEndTag());
    verify("Another message for testDoEndTagMessageMarkerNoException WARN M-E01 E");
}
项目:log4j2    文件:LoggingMessageTagSupportTest.java   
@Test
public void testDoEndTagMessageMarkerException() throws Exception {
    this.setUp(Level.ERROR);

    this.tag.setException(new RuntimeException("This is another test"));
    this.tag.setMarker(MarkerManager.getMarker("F02"));
    this.tag.setMessage(
            logger.getMessageFactory().newMessage("Final message for testDoEndTagMessageMarkerException")
    );

    assertEquals("The return value is not correct.", BodyTag.EVAL_PAGE, this.tag.doEndTag());
    verify("Final message for testDoEndTagMessageMarkerException ERROR M-F02 E java.lang.RuntimeException: " +
            "This is another test");
}
项目:log4j2    文件:LoggingMessageTagSupportTest.java   
@Test
public void testDoEndTagObjectMarkerNoException() throws Exception {
    this.setUp(Level.WARN);

    this.tag.setMarker(MarkerManager.getMarker("E01"));
    this.tag.setMessage(new MyMessage("Another message for testDoEndTagObjectMarkerNoException"));

    assertEquals("The return value is not correct.", BodyTag.EVAL_PAGE, this.tag.doEndTag());
    verify("Another message for testDoEndTagObjectMarkerNoException WARN M-E01 E");
}
项目:log4j2    文件:LoggingMessageTagSupportTest.java   
@Test
public void testDoEndTagObjectMarkerException() throws Exception {
    this.setUp(Level.ERROR);

    this.tag.setException(new RuntimeException("This is another test"));
    this.tag.setMarker(MarkerManager.getMarker("F02"));
    this.tag.setMessage(new MyMessage("Final message for testDoEndTagObjectMarkerException"));

    assertEquals("The return value is not correct.", BodyTag.EVAL_PAGE, this.tag.doEndTag());
    verify("Final message for testDoEndTagObjectMarkerException ERROR M-F02 E java.lang.RuntimeException: " +
            "This is another test");
}
项目:log4j2    文件:IfEnabledTagTest.java   
@Test
public void testDoStartTagEnabledStringMarker() throws Exception {
    this.tag.setMarker(MarkerManager.getMarker("E01"));
    this.tag.setLevel("error");

    assertEquals("The return value is not correct.", Tag.EVAL_BODY_INCLUDE, this.tag.doStartTag());
}
项目:log4j2    文件:IfEnabledTagTest.java   
@Test
public void testDoStartTagEnabledLevelMarker() throws Exception {
    this.tag.setMarker(MarkerManager.getMarker("F02"));
    this.tag.setLevel(Level.ERROR);

    assertEquals("The return value is not correct.", Tag.EVAL_BODY_INCLUDE, this.tag.doStartTag());
}
项目:log4j2    文件:IfEnabledTagTest.java   
@Test
public void testDoStartTagDisabledStringMarker() throws Exception {
    this.tag.setMarker(MarkerManager.getMarker("E01"));
    this.tag.setLevel("trace");

    assertEquals("The return value is not correct.", Tag.SKIP_BODY, this.tag.doStartTag());
}
项目:log4j2    文件:IfEnabledTagTest.java   
@Test
public void testDoStartTagDisabledLevelMarker() throws Exception {
    this.tag.setMarker(MarkerManager.getMarker("F02"));
    this.tag.setLevel(Level.TRACE);

    assertEquals("The return value is not correct.", Tag.SKIP_BODY, this.tag.doStartTag());
}
项目:log4j2    文件:MarkerTest.java   
@Test
public void testMarker() {
    final org.slf4j.Marker slf4jMarker = org.slf4j.MarkerFactory.getMarker("TEST");
    final org.slf4j.Marker slf4jParent = org.slf4j.MarkerFactory.getMarker("PARENT");
    slf4jMarker.add(slf4jParent);
    final Marker log4jParent = MarkerManager.getMarker("PARENT");
    final Marker log4jMarker = MarkerManager.getMarker("TEST", log4jParent);

    assertTrue("Incorrect Marker class", slf4jMarker instanceof MarkerWrapper);
    assertTrue("SLF4J Marker doesn't match Log4j Marker", ((MarkerWrapper) slf4jMarker).isInstanceOf(log4jMarker));
    assertTrue("SLF4J Parent doesn't match Log4j parent", ((MarkerWrapper) slf4jMarker).isInstanceOf(log4jParent));
}
项目:log4j2    文件:FlumePersistentAppenderTest.java   
@Test
public void testSingle() throws InterruptedException, IOException {

    final Logger logger = LogManager.getLogger("EventLogger");
    final Marker marker = MarkerManager.getMarker("EVENT");
    logger.info(marker, "This is a test message");

    final Event event = primary.poll();
    Assert.assertNotNull(event);
    final String body = getBody(event);
    Assert.assertTrue("Channel contained event, but not expected message. Received: " + body,
        body.endsWith("This is a test message"));
}
项目:log4j2    文件:MarkerAttributeConverter.java   
@Override
public Marker convertToEntityAttribute(final String s) {
    if (Strings.isEmpty(s)) {
        return null;
    }

    final int bracket = s.indexOf("[");

    return bracket < 1 ? MarkerManager.getMarker(s) : MarkerManager.getMarker(s.substring(0, bracket));
}
项目:log4j2    文件:MarkerPatternConverterTest.java   
@Test
public void testLookup() {
    final Message msg = new StructuredDataMessage("Test", "This is a test", "Audit");
    final Marker eventMarker = MarkerManager.getMarker("EVENT");
    final Marker auditMarker = MarkerManager.getMarker("AUDIT", eventMarker);
    final LogEvent event = new Log4jLogEvent("MyLogger", auditMarker, null, Level.DEBUG, msg, null);
    final StringBuilder sb = new StringBuilder();
    final MarkerPatternConverter converter = MarkerPatternConverter.newInstance(null);
    converter.format(event, sb);
    assertEquals(auditMarker.toString(), sb.toString());
}
项目:log4j2    文件:MapRewritePolicyTest.java   
@BeforeClass
public static void setupClass() {
    map.put("test1", "one");
    map.put("test2", "two");
    logEvent0 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ERROR,
    new SimpleMessage("Test"), new RuntimeException("test"), map, null, "none",
    new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 28), 2);
    logEvent1 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ERROR,
    new MapMessage(map), null, map, null, "none",
    new StackTraceElement("MapRewritePolicyTest", "setupClass", "MapRewritePolicyTest", 29), 2);
final ThreadContextStack stack = new MutableThreadContextStack(new ArrayList<String>(map.values()));
    logEvent2 = new Log4jLogEvent("test", MarkerManager.getMarker("test"), "MapRewritePolicyTest.setupClass()",
    Level.TRACE, new StructuredDataMessage("test", "Nothing", "test", map), new RuntimeException("test"), null,
    stack, "none", new StackTraceElement("MapRewritePolicyTest",
    "setupClass", "MapRewritePolicyTest", 30), 20000000);
    logEvent3 = new Log4jLogEvent("test", null, "MapRewritePolicyTest.setupClass()", Level.ALL, new MapMessage(map),
    null, map, stack, null, new StackTraceElement("MapRewritePolicyTest",
    "setupClass", "MapRewritePolicyTest", 31), Long.MAX_VALUE);
    rewrite = new KeyValuePair[] {new KeyValuePair("test2", "2"), new KeyValuePair("test3", "three")};
}