use of org.apache.logging.log4j.core.net.Severity in project logging-log4j2 by apache.
the class JsonTemplateLayoutTest method test_level_severity.
@Test
void test_level_severity() {
// Create the event template.
final String eventTemplate = writeJson(asMap("severityKeyword", asMap("$resolver", "level", "field", "severity", "severity", asMap("field", "keyword")), "severityCode", asMap("$resolver", "level", "field", "severity", "severity", asMap("field", "code"))));
// Create the layout.
final JsonTemplateLayout layout = JsonTemplateLayout.newBuilder().setConfiguration(CONFIGURATION).setEventTemplate(eventTemplate).build();
for (final Level level : Level.values()) {
// Create the log event.
final SimpleMessage message = new SimpleMessage("Hello, World!");
final LogEvent logEvent = Log4jLogEvent.newBuilder().setLoggerName(LOGGER_NAME).setLevel(level).setMessage(message).build();
// Check the serialized event.
usingSerializedLogEventAccessor(layout, logEvent, accessor -> {
final Severity expectedSeverity = Severity.getSeverity(level);
final String expectedSeverityKeyword = expectedSeverity.name();
final int expectedSeverityCode = expectedSeverity.getCode();
assertThat(accessor.getString("severityKeyword")).isEqualTo(expectedSeverityKeyword);
assertThat(accessor.getInteger("severityCode")).isEqualTo(expectedSeverityCode);
});
}
}
Aggregations