use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class PatternLayoutComparisonBenchmark method createLog4j2Event.
private static LogEvent createLog4j2Event() {
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 Map<String, String> 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).setContextMap(//
mdc).setContextStack(//
ndc).setThreadName(//
threadName).setSource(//
location).setTimeMillis(//
timestamp).build();
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class AsyncLoggerConfigUseAfterShutdownTest method testNoErrorIfLogAfterShutdown.
@Test
public void testNoErrorIfLogAfterShutdown() throws Exception {
final Logger log = LogManager.getLogger("com.foo.Bar");
log.info("some message");
// stop async thread
CoreLoggerContexts.stopLoggerContext();
// call the #logMessage() method to bypass the isEnabled check:
// before the LOG4J2-639 fix this would throw a NPE
((AbstractLogger) log).logMessage("com.foo.Bar", Level.INFO, null, new SimpleMessage("msg"), null);
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class AsyncLoggerUseAfterShutdownTest method testNoErrorIfLogAfterShutdown.
@Test
public void testNoErrorIfLogAfterShutdown() throws Exception {
final Logger log = LogManager.getLogger("com.foo.Bar");
final String msg = "Async logger msg";
log.info(msg, new InternalError("this is not a real error"));
// stop async thread
CoreLoggerContexts.stopLoggerContext();
// call the #logMessage() method to bypass the isEnabled check:
// before the LOG4J2-639 fix this would throw a NPE
((AbstractLogger) log).logMessage("com.foo.Bar", Level.INFO, null, new SimpleMessage("msg"), null);
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class Log4jLogger method log.
@Override
public void log(final Marker marker, final String fqcn, final int level, final String message, final Object[] params, Throwable throwable) {
final Level log4jLevel = getLevel(level);
final org.apache.logging.log4j.Marker log4jMarker = getMarker(marker);
if (!logger.isEnabled(log4jLevel, log4jMarker, message, params)) {
return;
}
final Message msg;
if (eventLogger && marker != null && marker.contains(EVENT_MARKER) && converter != null) {
msg = converter.convertEvent(message, params, throwable);
} else if (params == null) {
msg = new SimpleMessage(message);
} else {
msg = new ParameterizedMessage(message, params, throwable);
if (throwable != null) {
throwable = msg.getThrowable();
}
}
logger.logMessage(fqcn, log4jLevel, log4jMarker, msg, throwable);
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class AbstractLogger method entryMsg.
protected EntryMessage entryMsg(final String format, final Object... params) {
final int count = params == null ? 0 : params.length;
if (count == 0) {
if (Strings.isEmpty(format)) {
return flowMessageFactory.newEntryMessage(null);
}
return flowMessageFactory.newEntryMessage(new SimpleMessage(format));
}
if (format != null) {
return flowMessageFactory.newEntryMessage(new ParameterizedMessage(format, params));
}
final StringBuilder sb = new StringBuilder();
sb.append("params(");
for (int i = 0; i < count; i++) {
if (i > 0) {
sb.append(", ");
}
final Object parm = params[i];
sb.append(parm instanceof Message ? ((Message) parm).getFormattedMessage() : String.valueOf(parm));
}
sb.append(')');
return flowMessageFactory.newEntryMessage(new SimpleMessage(sb));
}
Aggregations