use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class ThrowablePatternConverterTest method testShortLocalizedMessage.
@Test
public void testShortLocalizedMessage() {
final String[] options = { "short.localizedMessage" };
final ThrowablePatternConverter converter = ThrowablePatternConverter.newInstance(null, options);
final Throwable parent = new LocalizedException();
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", "I am localized.", result);
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class VariablesNotEmptyReplacementConverterTest method testReplacement.
private void testReplacement(final String tag, final String expectedValue) {
final LogEvent event = //
Log4jLogEvent.newBuilder().setLoggerName(//
VariablesNotEmptyReplacementConverterTest.class.getName()).setLevel(//
Level.DEBUG).setMessage(//
new SimpleMessage("This is a test")).build();
final StringBuilder sb = new StringBuilder();
final LoggerContext ctx = LoggerContext.getContext();
final String[] options = new String[] { "[" + tag + "]" };
final VariablesNotEmptyReplacementConverter converter = VariablesNotEmptyReplacementConverter.newInstance(ctx.getConfiguration(), options);
converter.format(event, sb);
assertEquals(expectedValue, sb.toString());
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class JmsAppenderIT method testLogObjectMessageToQueue.
@Test
public void testLogObjectMessageToQueue() throws Exception {
setUp(SerializedLayout.createLayout());
final int messageCount = 100;
final MessageConsumer messageConsumer = jmsManager.createMessageConsumer();
final JmsQueueConsumer consumer = new JmsQueueConsumer(messageCount, ObjectMessage.class);
messageConsumer.setMessageListener(consumer);
final String messageText = "Hello, World!";
final String loggerName = this.getClass().getName();
for (int i = 0; i < messageCount; i++) {
final LogEvent event = //
Log4jLogEvent.newBuilder().setLoggerName(loggerName).setLoggerFqcn(loggerName).setLevel(//
Level.INFO).setMessage(new SimpleMessage(messageText)).setThreadName(//
Thread.currentThread().getName()).setTimeMillis(System.currentTimeMillis()).build();
appender.append(event);
}
consumer.awaitAndAssertAllMessagesConsumed();
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class Logger method logMessage.
@Override
public void logMessage(final String fqcn, final Level level, final Marker marker, final Message message, final Throwable t) {
final Message msg = message == null ? new SimpleMessage(Strings.EMPTY) : message;
final ReliabilityStrategy strategy = privateConfig.loggerConfig.getReliabilityStrategy();
strategy.log(this, getName(), fqcn, marker, level, msg, t);
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class ConsoleAppenderTest method testConsoleStreamManagerDoesNotClose.
private void testConsoleStreamManagerDoesNotClose(final PrintStream ps, final Target targetName, final SystemSetter systemSetter) {
try {
systemSetter.systemSet(psMock);
final Layout<String> layout = PatternLayout.newBuilder().withAlwaysWriteExceptions(true).build();
final ConsoleAppender app = ConsoleAppender.newBuilder().withLayout(layout).setTarget(targetName).withName("Console").withIgnoreExceptions(false).build();
app.start();
assertTrue("Appender did not start", app.isStarted());
final LogEvent event = //
Log4jLogEvent.newBuilder().setLoggerName(//
"TestLogger").setLoggerFqcn(//
ConsoleAppenderTest.class.getName()).setLevel(//
Level.INFO).setMessage(//
new SimpleMessage("Test")).build();
app.append(event);
app.stop();
assertFalse("Appender did not stop", app.isStarted());
} finally {
systemSetter.systemSet(ps);
}
then(psMock).should(atLeastOnce()).write(any(byte[].class), anyInt(), anyInt());
then(psMock).should(atLeastOnce()).flush();
}
Aggregations