From 32f426475b7b440fc11066f7de97bde9277f5c05 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Sat, 6 Mar 2021 07:55:15 -0800 Subject: [PATCH 1/2] ConsoleLogRecordExporter modified to support Message and StateValues --- .../CHANGELOG.md | 1 + .../ConsoleLogRecordExporter.cs | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md index 4991c7ddff1..cef9b4af893 100644 --- a/src/OpenTelemetry.Exporter.Console/CHANGELOG.md +++ b/src/OpenTelemetry.Exporter.Console/CHANGELOG.md @@ -11,6 +11,7 @@ please check the latest changes * Removed code that prints Baggage information ([#1825](https://github.com/open-telemetry/opentelemetry-dotnet/pull/1825)) +* LogRecordExporter exports Message and StateValues from LogRecord. ## 1.0.1 diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs b/src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs index 6e2c5de2d42..9311635ec01 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs @@ -39,7 +39,24 @@ public override ExportResult Export(in Batch batch) this.WriteLine($"{"LogRecord.CategoryName:".PadRight(rightPaddingLength)}{logRecord.CategoryName}"); this.WriteLine($"{"LogRecord.LogLevel:".PadRight(rightPaddingLength)}{logRecord.LogLevel}"); this.WriteLine($"{"LogRecord.TraceFlags:".PadRight(rightPaddingLength)}{logRecord.TraceFlags}"); - this.WriteLine($"{"LogRecord.State:".PadRight(rightPaddingLength)}{logRecord.State}"); + if (logRecord.Message != null) + { + this.WriteLine($"{"LogRecord.Message:".PadRight(rightPaddingLength)}{logRecord.Message}"); + } + + if (logRecord.State != null) + { + this.WriteLine($"{"LogRecord.State:".PadRight(rightPaddingLength)}{logRecord.State}"); + } + else if (logRecord.StateValues != null) + { + this.WriteLine("LogRecord.StateValues (Key:Value):"); + for (int i = 0; i < logRecord.StateValues.Count; i++) + { + this.WriteLine($"{logRecord.StateValues[i].Key.PadRight(rightPaddingLength)}:{logRecord.StateValues[i].Value}"); + } + } + if (logRecord.Exception is { }) { this.WriteLine($"{"LogRecord.Exception:".PadRight(rightPaddingLength)}{logRecord.Exception?.Message}"); From 034fd72e4920b6585be39f1d6bee87fe5d994932 Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Mon, 8 Mar 2021 08:14:08 -0800 Subject: [PATCH 2/2] slighty better printing --- src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs b/src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs index 9311635ec01..532c6a29728 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs @@ -53,7 +53,7 @@ public override ExportResult Export(in Batch batch) this.WriteLine("LogRecord.StateValues (Key:Value):"); for (int i = 0; i < logRecord.StateValues.Count; i++) { - this.WriteLine($"{logRecord.StateValues[i].Key.PadRight(rightPaddingLength)}:{logRecord.StateValues[i].Value}"); + this.WriteLine($"{logRecord.StateValues[i].Key.PadRight(rightPaddingLength)}{logRecord.StateValues[i].Value}"); } }