use of org.apache.logging.log4j.message.SimpleMessage in project Railcraft by Railcraft.
the class Game method logThrowable.
public static void logThrowable(Level level, int lines, Throwable error, String msg, Object... args) {
log(level, msg, args);
log(level, new SimpleMessage(error.toString()));
logTrace(level, lines, 0, error.getStackTrace());
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class ScriptFilter method filter.
@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final Object msg, final Throwable t) {
final SimpleBindings bindings = new SimpleBindings();
bindings.put("logger", logger);
bindings.put("level", level);
bindings.put("marker", marker);
bindings.put("message", msg instanceof String ? new SimpleMessage((String) msg) : new ObjectMessage(msg));
bindings.put("parameters", null);
bindings.put("throwable", t);
bindings.putAll(configuration.getProperties());
bindings.put("substitutor", configuration.getStrSubstitutor());
final Object object = configuration.getScriptManager().execute(script.getName(), bindings);
return object == null || !Boolean.TRUE.equals(object) ? onMismatch : onMatch;
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class YamlLayoutTest method testLayoutLoggerName.
@Test
public void testLayoutLoggerName() throws Exception {
final AbstractJacksonLayout layout = YamlLayout.createLayout(null, false, false, null, null, StandardCharsets.UTF_8, true);
final Log4jLogEvent expected = //
Log4jLogEvent.newBuilder().setLoggerName(//
"a.B").setLoggerFqcn(//
"f.q.c.n").setLevel(//
Level.DEBUG).setMessage(//
new SimpleMessage("M")).setThreadName(//
"threadName").setTimeMillis(1).build();
final String str = layout.toSerializable(expected);
assertTrue(str, str.contains("loggerName: \"a.B\""));
final Log4jLogEvent actual = new Log4jYamlObjectMapper(false, true).readValue(str, Log4jLogEvent.class);
assertEquals(expected.getLoggerName(), actual.getLoggerName());
assertEquals(expected, actual);
}
use of org.apache.logging.log4j.message.SimpleMessage in project logging-log4j2 by apache.
the class StringBuilderPool method createLog4j2Event.
private static LogEvent createLog4j2Event() {
final Marker marker = null;
final String fqcn = "com.mycom.myproject.mypackage.MyClass";
final Level level = Level.DEBUG;
// length=32
final String STR = "AB!(%087936DZYXQWEIOP$#^~-=/><nb";
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 JsonLayoutTest method testLayoutLoggerName.
@Test
public void testLayoutLoggerName() throws Exception {
final boolean propertiesAsList = false;
// @formatter:off
final AbstractJacksonLayout layout = JsonLayout.newBuilder().setLocationInfo(false).setProperties(false).setPropertiesAsList(propertiesAsList).setComplete(false).setCompact(true).setEventEol(false).setCharset(StandardCharsets.UTF_8).setIncludeStacktrace(true).build();
// @formatter:on
// @formatter:off
final Log4jLogEvent expected = Log4jLogEvent.newBuilder().setLoggerName("a.B").setLoggerFqcn("f.q.c.n").setLevel(Level.DEBUG).setMessage(new SimpleMessage("M")).setThreadName("threadName").setTimeMillis(1).build();
// @formatter:on
final String str = layout.toSerializable(expected);
assertTrue(str, str.contains("\"loggerName\":\"a.B\""));
final Log4jLogEvent actual = new Log4jJsonObjectMapper(propertiesAsList, true).readValue(str, Log4jLogEvent.class);
assertEquals(expected.getLoggerName(), actual.getLoggerName());
assertEquals(expected, actual);
}
Aggregations