use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class Log4j2AppenderComparisonBenchmark method createLogEvent.
private static LogEvent createLogEvent() {
final Marker marker = null;
final String fqcn = "com.mycom.myproject.mypackage.MyClass";
final Level level = Level.DEBUG;
final Message message = new SimpleMessage(MESSAGE);
final Throwable t = null;
final StringMap mdc = null;
final ThreadContext.ContextStack ndc = null;
final String threadName = "THREAD";
final StackTraceElement location = null;
final long timestamp = System.currentTimeMillis();
return //
Log4jLogEvent.newBuilder().setLoggerName(//
"name(ignored)").setMarker(//
marker).setLoggerFqcn(//
fqcn).setLevel(//
level).setMessage(//
message).setThrown(//
t).setContextData(//
mdc).setContextStack(//
ndc).setThreadName(//
threadName).setSource(//
location).setTimeMillis(//
timestamp).build();
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class PatternLayoutBenchmark method createLogEvent.
private static LogEvent createLogEvent() {
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 StringMap 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).setContextData(//
mdc).setContextStack(//
ndc).setThreadName(//
threadName).setSource(//
location).setTimeMillis(//
timestamp).build();
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class RingBufferLogEventTest method testCreateMementoRetainsParametersAndFormat.
@Test
public void testCreateMementoRetainsParametersAndFormat() {
final RingBufferLogEvent evt = new RingBufferLogEvent();
// Initialize the event with parameters
evt.swapParameters(new Object[10]);
final String loggerName = "logger.name";
final Marker marker = MarkerManager.getMarker("marked man");
final String fqcn = "f.q.c.n";
final Level level = Level.TRACE;
final ReusableMessageFactory factory = new ReusableMessageFactory();
final Message message = factory.newMessage("Hello {}!", "World");
try {
final Throwable t = new InternalError("not a real error");
final ContextStack contextStack = new MutableThreadContextStack(Arrays.asList("a", "b"));
final String threadName = "main";
final StackTraceElement location = null;
evt.setValues(null, loggerName, marker, fqcn, level, message, t, (StringMap) evt.getContextData(), contextStack, -1, threadName, -1, location, new FixedPreciseClock(12345, 678), new DummyNanoClock(1));
((StringMap) evt.getContextData()).putValue("key", "value");
final Message actual = evt.createMemento().getMessage();
assertEquals("Hello {}!", actual.getFormat());
assertArrayEquals(new String[] { "World" }, actual.getParameters());
assertEquals("Hello World!", actual.getFormattedMessage());
} finally {
ReusableMessageFactory.release(message);
}
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class RingBufferLogEventTest method testIsPopulated.
/**
* @see <a href="https://issues.apache.org/jira/browse/LOG4J2-2816">LOG4J2-2816</a>
*/
@Test
public void testIsPopulated() {
final RingBufferLogEvent evt = new RingBufferLogEvent();
assertFalse(evt.isPopulated());
final String loggerName = null;
final Marker marker = null;
final String fqcn = null;
final Level level = null;
final Message data = null;
final Throwable t = null;
final ContextStack contextStack = null;
final String threadName = null;
final StackTraceElement location = null;
evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(), contextStack, -1, threadName, -1, location, new FixedPreciseClock(), new DummyNanoClock(1));
assertTrue(evt.isPopulated());
evt.clear();
assertFalse(evt.isPopulated());
}
use of org.apache.logging.log4j.message.Message in project logging-log4j2 by apache.
the class RingBufferLogEventTest method testGetLevelReturnsOffIfNullLevelSet.
@Test
public void testGetLevelReturnsOffIfNullLevelSet() {
final RingBufferLogEvent evt = new RingBufferLogEvent();
final String loggerName = null;
final Marker marker = null;
final String fqcn = null;
final Level level = null;
final Message data = null;
final Throwable t = null;
final ContextStack contextStack = null;
final String threadName = null;
final StackTraceElement location = null;
evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(), contextStack, -1, threadName, -1, location, new FixedPreciseClock(), new DummyNanoClock(1));
assertEquals(Level.OFF, evt.getLevel());
}
Aggregations