@Test void testSingleNDCInformationLogging() throws Exception { record.setNdc("exampleTag"); JsonNode result = objectMapper.readTree(formatter.format(record)); assertThat(result.get("tags")).hasSize(1); assertThat(result.get("tags").get(0).textValue()).isEqualTo("exampleTag"); }
@Override public String format(ExtLogRecord record) { StringBuilder builder = new StringBuilder(); EcsJsonSerializer.serializeObjectStart(builder, record.getMillis()); EcsJsonSerializer.serializeLogLevel(builder, record.getLevel().getName()); EcsJsonSerializer.serializeFormattedMessage(builder, record.getFormattedMessage()); EcsJsonSerializer.serializeServiceName(builder, serviceName); EcsJsonSerializer.serializeEventDataset(builder, eventDataset); EcsJsonSerializer.serializeThreadName(builder, record.getThreadName()); EcsJsonSerializer.serializeLoggerName(builder, record.getLoggerName()); EcsJsonSerializer.serializeMDC(builder, record.getMdcCopy()); String ndc = record.getNdc(); if (ndc != null && !ndc.isEmpty()) { EcsJsonSerializer.serializeTagStart(builder); for (String tag : ndc.split("\\.")) { EcsJsonSerializer.serializeSingleTag(builder, tag); } EcsJsonSerializer.serializeTagEnd(builder); } if (includeOrigin && record.getSourceFileName() != null && record.getSourceMethodName() != null) { EcsJsonSerializer.serializeOrigin(builder, record.getSourceFileName(), record.getSourceMethodName(), record.getSourceLineNumber()); } Throwable throwable = record.getThrown(); if (throwable != null) { EcsJsonSerializer.serializeException(builder, throwable, stackTraceAsArray); } EcsJsonSerializer.serializeObjectEnd(builder); return builder.toString(); }
EcsFormatter extends ExtFormatter { @Override public String format(ExtLogRecord record) { StringBuilder builder = new StringBuilder(); EcsJsonSerializer.serializeObjectStart(builder, record.getMillis()); EcsJsonSerializer.serializeLogLevel(builder, record.getLevel().getName()); EcsJsonSerializer.serializeFormattedMessage(builder, record.getFormattedMessage()); EcsJsonSerializer.serializeServiceName(builder, serviceName); EcsJsonSerializer.serializeEventDataset(builder, eventDataset); EcsJsonSerializer.serializeThreadName(builder, record.getThreadName()); EcsJsonSerializer.serializeLoggerName(builder, record.getLoggerName()); EcsJsonSerializer.serializeMDC(builder, record.getMdcCopy()); String ndc = record.getNdc(); if (ndc != null && !ndc.isEmpty()) { EcsJsonSerializer.serializeTagStart(builder); for (String tag : ndc.split("\\.")) { EcsJsonSerializer.serializeSingleTag(builder, tag); } EcsJsonSerializer.serializeTagEnd(builder); } if (includeOrigin && record.getSourceFileName() != null && record.getSourceMethodName() != null) { EcsJsonSerializer.serializeOrigin(builder, record.getSourceFileName(), record.getSourceMethodName(), record.getSourceLineNumber()); } Throwable throwable = record.getThrown(); if (throwable != null) { EcsJsonSerializer.serializeException(builder, throwable, stackTraceAsArray); } EcsJsonSerializer.serializeObjectEnd(builder); return builder.toString(); } }
EcsFormatter extends ExtFormatter { @Override public String format(ExtLogRecord record) { StringBuilder builder = new StringBuilder(); EcsJsonSerializer.serializeObjectStart(builder, record.getMillis()); EcsJsonSerializer.serializeLogLevel(builder, record.getLevel().getName()); EcsJsonSerializer.serializeFormattedMessage(builder, record.getFormattedMessage()); EcsJsonSerializer.serializeServiceName(builder, serviceName); EcsJsonSerializer.serializeEventDataset(builder, eventDataset); EcsJsonSerializer.serializeThreadName(builder, record.getThreadName()); EcsJsonSerializer.serializeLoggerName(builder, record.getLoggerName()); EcsJsonSerializer.serializeMDC(builder, record.getMdcCopy()); String ndc = record.getNdc(); if (ndc != null && !ndc.isEmpty()) { EcsJsonSerializer.serializeTagStart(builder); for (String tag : ndc.split("\\.")) { EcsJsonSerializer.serializeSingleTag(builder, tag); } EcsJsonSerializer.serializeTagEnd(builder); } if (includeOrigin && record.getSourceFileName() != null && record.getSourceMethodName() != null) { EcsJsonSerializer.serializeOrigin(builder, record.getSourceFileName(), record.getSourceMethodName(), record.getSourceLineNumber()); } Throwable throwable = record.getThrown(); if (throwable != null) { EcsJsonSerializer.serializeException(builder, throwable, stackTraceAsArray); } EcsJsonSerializer.serializeObjectEnd(builder); return builder.toString(); } EcsFormatter(); }
EcsFormatter extends ExtFormatter { @Override public String format(ExtLogRecord record) { StringBuilder builder = new StringBuilder(); EcsJsonSerializer.serializeObjectStart(builder, record.getMillis()); EcsJsonSerializer.serializeLogLevel(builder, record.getLevel().getName()); EcsJsonSerializer.serializeFormattedMessage(builder, record.getFormattedMessage()); EcsJsonSerializer.serializeServiceName(builder, serviceName); EcsJsonSerializer.serializeEventDataset(builder, eventDataset); EcsJsonSerializer.serializeThreadName(builder, record.getThreadName()); EcsJsonSerializer.serializeLoggerName(builder, record.getLoggerName()); EcsJsonSerializer.serializeMDC(builder, record.getMdcCopy()); String ndc = record.getNdc(); if (ndc != null && !ndc.isEmpty()) { EcsJsonSerializer.serializeTagStart(builder); for (String tag : ndc.split("\\.")) { EcsJsonSerializer.serializeSingleTag(builder, tag); } EcsJsonSerializer.serializeTagEnd(builder); } if (includeOrigin && record.getSourceFileName() != null && record.getSourceMethodName() != null) { EcsJsonSerializer.serializeOrigin(builder, record.getSourceFileName(), record.getSourceMethodName(), record.getSourceLineNumber()); } Throwable throwable = record.getThrown(); if (throwable != null) { EcsJsonSerializer.serializeException(builder, throwable, stackTraceAsArray); } EcsJsonSerializer.serializeObjectEnd(builder); return builder.toString(); } EcsFormatter(); @Override String format(ExtLogRecord record); void setIncludeOrigin(final boolean includeOrigin); void setServiceName(final String serviceName); void setStackTraceAsArray(final boolean stackTraceAsArray); void setEventDataset(String eventDataset); }
EcsFormatter extends ExtFormatter { @Override public String format(ExtLogRecord record) { StringBuilder builder = new StringBuilder(); EcsJsonSerializer.serializeObjectStart(builder, record.getMillis()); EcsJsonSerializer.serializeLogLevel(builder, record.getLevel().getName()); EcsJsonSerializer.serializeFormattedMessage(builder, record.getFormattedMessage()); EcsJsonSerializer.serializeServiceName(builder, serviceName); EcsJsonSerializer.serializeEventDataset(builder, eventDataset); EcsJsonSerializer.serializeThreadName(builder, record.getThreadName()); EcsJsonSerializer.serializeLoggerName(builder, record.getLoggerName()); EcsJsonSerializer.serializeMDC(builder, record.getMdcCopy()); String ndc = record.getNdc(); if (ndc != null && !ndc.isEmpty()) { EcsJsonSerializer.serializeTagStart(builder); for (String tag : ndc.split("\\.")) { EcsJsonSerializer.serializeSingleTag(builder, tag); } EcsJsonSerializer.serializeTagEnd(builder); } if (includeOrigin && record.getSourceFileName() != null && record.getSourceMethodName() != null) { EcsJsonSerializer.serializeOrigin(builder, record.getSourceFileName(), record.getSourceMethodName(), record.getSourceLineNumber()); } Throwable throwable = record.getThrown(); if (throwable != null) { EcsJsonSerializer.serializeException(builder, throwable, stackTraceAsArray); } EcsJsonSerializer.serializeObjectEnd(builder); return builder.toString(); } EcsFormatter(); @Override String format(ExtLogRecord record); void setIncludeOrigin(final boolean includeOrigin); void setServiceName(final String serviceName); void setStackTraceAsArray(final boolean stackTraceAsArray); void setEventDataset(String eventDataset);  }