use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class LambdaUtilTest method testGetMessageSupplierResultOfSupplier.
@Test
public void testGetMessageSupplierResultOfSupplier() {
final Message expected = new SimpleMessage("hi");
final Message actual = LambdaUtil.get(new MessageSupplier() {
@Override
public Message get() {
return expected;
}
});
assertSame(expected, actual);
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class LoggerSupplierTest method flowTracing_SupplierOfSimpleMessage.
@Test
public void flowTracing_SupplierOfSimpleMessage() {
logger.traceEntry(new Supplier<SimpleMessage>() {
@Override
public SimpleMessage get() {
return new SimpleMessage("1234567890");
}
});
assertEquals(1, results.size());
assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter"));
assertThat("Missing entry data", results.get(0), containsString("(1234567890)"));
assertThat("Bad toString()", results.get(0), not(containsString("SimpleMessage")));
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class LoggerNameLevelRewritePolicyTest method testUpdate.
@Test
public void testUpdate() {
final KeyValuePair[] rewrite = new KeyValuePair[] { new KeyValuePair("INFO", "DEBUG"), new KeyValuePair("WARN", "INFO") };
final String loggerNameRewrite = "com.foo.bar";
LogEvent logEvent = Log4jLogEvent.newBuilder().setLoggerName(loggerNameRewrite).setLoggerFqcn("LoggerNameLevelRewritePolicyTest.testUpdate()").setLevel(Level.INFO).setMessage(new SimpleMessage("Test")).setThrown(new RuntimeException("test")).setThreadName("none").setTimeMillis(1).build();
final LoggerNameLevelRewritePolicy updatePolicy = LoggerNameLevelRewritePolicy.createPolicy(loggerNameRewrite, rewrite);
LogEvent rewritten = updatePolicy.rewrite(logEvent);
Assert.assertEquals(Level.DEBUG, rewritten.getLevel());
logEvent = Log4jLogEvent.newBuilder().setLoggerName(loggerNameRewrite).setLoggerFqcn("LoggerNameLevelRewritePolicyTest.testUpdate()").setLevel(Level.WARN).setMessage(new SimpleMessage("Test")).setThrown(new RuntimeException("test")).setThreadName("none").setTimeMillis(1).build();
rewritten = updatePolicy.rewrite(logEvent);
Assert.assertEquals(Level.INFO, rewritten.getLevel());
final String loggerNameReadOnly = "com.nochange";
logEvent = Log4jLogEvent.newBuilder().setLoggerName(loggerNameReadOnly).setLoggerFqcn("LoggerNameLevelRewritePolicyTest.testUpdate()").setLevel(Level.INFO).setMessage(new SimpleMessage("Test")).setThrown(new RuntimeException("test")).setThreadName("none").setTimeMillis(1).build();
rewritten = updatePolicy.rewrite(logEvent);
Assert.assertEquals(Level.INFO, rewritten.getLevel());
logEvent = Log4jLogEvent.newBuilder().setLoggerName(loggerNameReadOnly).setLoggerFqcn("LoggerNameLevelRewritePolicyTest.testUpdate()").setLevel(Level.WARN).setMessage(new SimpleMessage("Test")).setThrown(new RuntimeException("test")).setThreadName("none").setTimeMillis(1).build();
rewritten = updatePolicy.rewrite(logEvent);
Assert.assertEquals(Level.WARN, rewritten.getLevel());
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class ThrowablePatternConverterTest method testShortFileName.
@Test
public void testShortFileName() {
final String[] options = { "short.fileName" };
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 file names should be same", "ThrowablePatternConverterTest.java", result);
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class ThrowablePatternConverterTest method testShortMethodName.
@Test
public void testShortMethodName() {
final String[] options = { "short.methodName" };
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 method names should be same", "testShortMethodName", result);
}
Aggregations