当前位置: 首页>>代码示例>>Java>>正文


Java SimpleMessage类代码示例

本文整理汇总了Java中org.apache.logging.log4j.message.SimpleMessage的典型用法代码示例。如果您正苦于以下问题:Java SimpleMessage类的具体用法?Java SimpleMessage怎么用?Java SimpleMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SimpleMessage类属于org.apache.logging.log4j.message包,在下文中一共展示了SimpleMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: launchCreatesAndStartsAppenderAndProcessesMessages

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
@Test
public void launchCreatesAndStartsAppenderAndProcessesMessages() throws Exception {
    final MessageInput messageInput = mock(MessageInput.class);
    transport.launch(messageInput);

    final DirectConsumingAppender appender = transport.getAppender();
    assertThat(appender.getName()).isEqualTo("graylog-plugin-internal-logs");
    assertThat(appender.getLayout()).isInstanceOf(SerializedLayout.class);
    assertThat(appender.isStarted()).isTrue();

    final MutableLogEvent logEvent = new MutableLogEvent();
    logEvent.setMessage(new SimpleMessage("Processed"));
    logEvent.setLevel(Level.ERROR);
    appender.append(logEvent);
    verify(messageInput, times(1)).processRawMessage(any(RawMessage.class));

    final MutableLogEvent ignoredLogEvent = new MutableLogEvent();
    ignoredLogEvent.setMessage(new SimpleMessage("Ignored"));
    ignoredLogEvent.setLevel(Level.TRACE);
    appender.append(ignoredLogEvent);
    verifyNoMoreInteractions(messageInput);
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-internal-logs,代码行数:23,代码来源:SerializedLogEventTransportTest.java

示例2: prepareLogEvent

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:29,代码来源:LoggingUtils.java

示例3: test_lineSeparator_suffix

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
@Test
public void test_lineSeparator_suffix() {

    // Create the log event.
    SimpleMessage message = new SimpleMessage("Hello, World!");
    LogEvent logEvent = Log4jLogEvent
            .newBuilder()
            .setLoggerName(LogstashLayoutTest.class.getSimpleName())
            .setLevel(Level.INFO)
            .setMessage(message)
            .build();

    // Check line separators.
    SoftAssertions assertions = new SoftAssertions();
    test_lineSeparator_suffix(logEvent, true, assertions);
    test_lineSeparator_suffix(logEvent, false, assertions);
    assertions.assertAll();

}
 
开发者ID:vy,项目名称:log4j2-logstash-layout,代码行数:20,代码来源:LogstashLayoutTest.java

示例4: createLogEvent

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
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();
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-internal-logs,代码行数:26,代码来源:SerializedLogEventCodecTest.java

示例5: newEvent

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
@Override
protected Object newEvent(LogDetails logDetails) {
    final Message message = new SimpleMessage(logDetails.getLogMessage());
    final StringMap contextData;
    if (!logDetails.getMdc().isEmpty()) {
        contextData = ContextDataFactory.createContextData();
        logDetails.getMdc().entrySet().forEach(it -> contextData.putValue(it.getKey(), it.getValue()));
    } else {
        contextData = null;
    }
    Log4jLogEvent.Builder builder = Log4jLogEvent.newBuilder().setLoggerName(logDetails.getClassName())
            .setTimeMillis(logDetails.getTimeMillis()).setLevel(Level.DEBUG).setContextData(contextData)
            .setIncludeLocation(logDetails.isLocationInfo()).setLoggerFqcn(logDetails.getClassName()).setMessage(message);
    if (logDetails.isLocationInfo()) {
        builder.setSource(new StackTraceElement(logDetails.getClassName(), logDetails.getMethodName(),
                logDetails.getFileName(), logDetails.getLineNumber()));
    }
    if (logDetails.getException() != null) {
        builder.setThrown(logDetails.getException());
    }
    return builder.build();
}
 
开发者ID:Talend,项目名称:daikon,代码行数:23,代码来源:Log4j2JSONLayoutTest.java

示例6: testFull

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
@Test
public void testFull() {
    final ExtendedThrowablePatternConverter converter = ExtendedThrowablePatternConverter.newInstance(null, null);
    final Throwable cause = new NullPointerException("null pointer");
    final Throwable parent = new IllegalArgumentException("IllegalArgument", cause);
    final LogEvent event = Log4jLogEvent.newBuilder() //
            .setLoggerName("testLogger") //
            .setLoggerFqcn(this.getClass().getName()) //
            .setLevel(Level.DEBUG) //
            .setMessage(new SimpleMessage("test exception")) //
            .setThrown(parent).build();
    final StringBuilder sb = new StringBuilder();
    converter.format(event, sb);
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    parent.printStackTrace(pw);
    String result = sb.toString();
    result = result.replaceAll(" ~?\\[.*\\]", Strings.EMPTY);
    final String expected = sw.toString(); //.replaceAll("\r", Strings.EMPTY);
    assertEquals(expected, result);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:22,代码来源:ExtendedThrowablePatternConverterTest.java

示例7: assertMessage

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
private void assertMessage(final String string, final InMemoryAppender app, final String header) {
    final LogEvent event = Log4jLogEvent.newBuilder() //
            .setLoggerName("TestLogger") //
            .setLoggerFqcn(InMemoryAppenderTest.class.getName()) //
            .setLevel(Level.INFO) //
            .setMessage(new SimpleMessage("Test")) //
            .build();
    app.start();
    assertTrue("Appender did not start", app.isStarted());
    app.append(event);
    app.append(event);
    final String msg = app.toString();
    assertNotNull("No message", msg);
    final String expectedHeader = header == null ? "" : header;
    final String expected = expectedHeader + "Test" + Strings.LINE_SEPARATOR + "Test" + Strings.LINE_SEPARATOR;
    assertTrue("Incorrect message: " + msg, msg.equals(expected));
    app.stop();
    assertFalse("Appender did not stop", app.isStarted());
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:20,代码来源:InMemoryAppenderTest.java

示例8: testReplacement

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
@Test
public void testReplacement() {
    ThreadContext.put("MyKey", "Apache");
    final LogEvent event = new Log4jLogEvent(RegexReplacementConverterTest.class.getName(), null, null,
        Level.DEBUG, new SimpleMessage("This is a test"), null);
    final StringBuilder sb = new StringBuilder();
    final LoggerContext ctx = (LoggerContext) LogManager.getContext();
    final String[] options = new String[] {
        "%logger %msg%n", "\\.", "/"
    };
    final RegexReplacementConverter converter = RegexReplacementConverter.newInstance(ctx.getConfiguration(),
        options);
    converter.format(event, sb);
    assertEquals("org/apache/logging/log4j/core/pattern/RegexReplacementConverterTest This is a test" +
        Constants.LINE_SEP, sb.toString());
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:17,代码来源:RegexReplacementConverterTest.java

示例9: testCustomPattern

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
/**
 * 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));
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:23,代码来源:PatternParserTest.java

示例10: testNestedPattern

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
@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));
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:18,代码来源:PatternParserTest.java

示例11: testFull

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
@Test
public void testFull() {
    final ExtendedThrowablePatternConverter converter = ExtendedThrowablePatternConverter.newInstance(null);
    final Throwable cause = new NullPointerException("null pointer");
    final Throwable parent = new IllegalArgumentException("IllegalArgument", cause);
    final LogEvent event = new Log4jLogEvent("testLogger", null, this.getClass().getName(), Level.DEBUG,
        new SimpleMessage("test exception"), parent);
    final StringBuilder sb = new StringBuilder();
    converter.format(event, sb);
    final StringWriter sw = new StringWriter();
    final PrintWriter pw = new PrintWriter(sw);
    parent.printStackTrace(pw);
    String result = sb.toString();
    result = result.replaceAll(" ~?\\[.*\\]", "");
    final String expected = sw.toString().replaceAll("\r", "");
    assertEquals(expected, result);
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:18,代码来源:ExtendedThrowablePatternConverterTest.java

示例12: testThresholds

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
@Test
public void testThresholds() {
    final ThresholdFilter filter = ThresholdFilter.createFilter(Level.ERROR, null, null);
    filter.start();
    assertTrue(filter.isStarted());
    assertSame(Filter.Result.DENY, filter.filter(null, Level.DEBUG, null, (Object) null, (Throwable) null));
    assertSame(Filter.Result.NEUTRAL, filter.filter(null, Level.ERROR, null, (Object) null, (Throwable) null));
    LogEvent event = Log4jLogEvent.newBuilder() //
            .setLevel(Level.DEBUG) //
            .setMessage(new SimpleMessage("Test")) //
            .build();
    assertSame(Filter.Result.DENY, filter.filter(event));
    event = Log4jLogEvent.newBuilder() //
            .setLevel(Level.ERROR) //
            .setMessage(new SimpleMessage("Test")) //
            .build();
    assertSame(Filter.Result.NEUTRAL, filter.filter(event));
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:19,代码来源:ThresholdFilterTest.java

示例13: testCrlfEscaping

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
@Test
public void testCrlfEscaping() {
    final LogEvent event = Log4jLogEvent.newBuilder() //
            .setLoggerName(EncodingPatternConverterTest.class.getName()) //
            .setLevel(Level.DEBUG) //
            .setMessage(new SimpleMessage("Test \r\n<div class=\"test\">this\r</div> & \n<div class='test'>that</div>"))
            .build();
    final StringBuilder sb = new StringBuilder();
    final LoggerContext ctx = LoggerContext.getContext();
    final String[] options = new String[]{"%msg", "CRLF"};
    final EncodingPatternConverter converter = EncodingPatternConverter
        .newInstance(ctx.getConfiguration(), options);
    assertNotNull("Error creating converter", converter);
    converter.format(event, sb);
    assertEquals(
        "Test \\r\\n<div class=\"test\">this\\r</div> & \\n<div class='test'>that</div>",
        sb.toString());
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:19,代码来源:EncodingPatternConverterTest.java

示例14: testUnixTimeMillis

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
@Test
public void testUnixTimeMillis() throws Exception {
    final PatternLayout layout = PatternLayout.newBuilder().withPattern("%d{UNIX_MILLIS} %m")
            .withConfiguration(ctx.getConfiguration()).build();
    final LogEvent event1 = Log4jLogEvent.newBuilder() //
            .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
            .setLevel(Level.INFO) //
            .setMessage(new SimpleMessage("Hello, world 1!")).build();
    final byte[] result1 = layout.toByteArray(event1);
    assertEquals(event1.getTimeMillis() + " Hello, world 1!", new String(result1));
    // System.out.println("event1=" + event1.getTimeMillis());
    final LogEvent event2 = Log4jLogEvent.newBuilder() //
            .setLoggerName(this.getClass().getName()).setLoggerFqcn("org.apache.logging.log4j.core.Logger") //
            .setLevel(Level.INFO) //
            .setMessage(new SimpleMessage("Hello, world 2!")).build();
    final byte[] result2 = layout.toByteArray(event2);
    assertEquals(event2.getTimeMillis() + " Hello, world 2!", new String(result2));
    // System.out.println("event2=" + event2.getTimeMillis());
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:20,代码来源:PatternLayoutTest.java

示例15: testShortMessage

import org.apache.logging.log4j.message.SimpleMessage; //导入依赖的package包/类
@Test
public void testShortMessage() {
    final String[] options = { "short.message" };
    final ThrowablePatternConverter converter = ThrowablePatternConverter.newInstance(null, options);
    final Throwable cause = new NullPointerException("null pointer");
    final Throwable parent = new IllegalArgumentException("IllegalArgument", cause);
    final LogEvent event = Log4jLogEvent.newBuilder() //
            .setLoggerName("testLogger") //
            .setLoggerFqcn(this.getClass().getName()) //
            .setLevel(Level.DEBUG) //
            .setMessage(new SimpleMessage("test exception")) //
            .setThrown(parent).build();
    final StringBuilder sb = new StringBuilder();
    converter.format(event, sb);
    final String result = sb.toString();
    assertEquals("The messages should be same", "IllegalArgument", result);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:18,代码来源:ThrowablePatternConverterTest.java


注:本文中的org.apache.logging.log4j.message.SimpleMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。