Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public CompletableResultCode flush() {
static void formatLog(StringBuilder stringBuilder, LogRecordData log) {
InstrumentationScopeInfo instrumentationScopeInfo = log.getInstrumentationScopeInfo();
Value<?> body = log.getBodyValue();
String severityText = log.getSeverityText();
String eventName = log.getEventName();
stringBuilder
.append(
Expand All @@ -73,6 +74,9 @@ static void formatLog(StringBuilder stringBuilder, LogRecordData log) {
.atZone(ZoneOffset.UTC)))
.append(" ")
.append(log.getSeverity());
if (severityText != null && !severityText.isEmpty()) {
stringBuilder.append(" [severityText: ").append(severityText).append("]");
}
if (eventName != null && !eventName.isEmpty()) {
stringBuilder.append(" [eventName: ").append(eventName).append("]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,34 @@ void format() {
+ "map=KeyValueList{{\"nested\":\"value\"}}}");
}

@Test
void formatWithSeverityText() {
long timestamp =
LocalDateTime.of(1970, Month.AUGUST, 7, 10, 0).toInstant(ZoneOffset.UTC).toEpochMilli();
LogRecordData log =
TestLogRecordData.builder()
.setResource(Resource.empty())
.setInstrumentationScopeInfo(
InstrumentationScopeInfo.builder("logTest").setVersion("1.0").build())
.setBody("message")
.setSeverity(Severity.ERROR3)
.setSeverityText("SEVERE")
.setTimestamp(timestamp, TimeUnit.MILLISECONDS)
.setSpanContext(
SpanContext.create(
"00000000000000010000000000000002",
"0000000000000003",
TraceFlags.getDefault(),
TraceState.getDefault()))
.build();
StringBuilder output = new StringBuilder();
SystemOutLogRecordExporter.formatLog(output, log);
assertThat(output.toString())
.isEqualTo(
"1970-08-07T10:00:00Z ERROR3 [severityText: SEVERE] 'message' : "
+ "00000000000000010000000000000002 0000000000000003 [scopeInfo: logTest:1.0] {}");
}

@Test
void formatWithEventName() {
long timestamp =
Expand Down
Loading