From 50baa250806301304333007a373aeb6451fc5a3a Mon Sep 17 00:00:00 2001 From: Cijo Thomas Date: Wed, 20 Apr 2022 13:37:52 -0700 Subject: [PATCH] ConsoleExporter Log minor cosmetic improvement. (#3211) --- .../ConsoleLogRecordExporter.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs b/src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs index da100c569ba..5872827659b 100644 --- a/src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs +++ b/src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs @@ -22,7 +22,7 @@ namespace OpenTelemetry.Exporter { public class ConsoleLogRecordExporter : ConsoleExporter { - private const int RightPaddingLength = 30; + private const int RightPaddingLength = 35; public ConsoleLogRecordExporter(ConsoleExporterOptions options) : base(options) @@ -33,14 +33,17 @@ public override ExportResult Export(in Batch batch) { foreach (var logRecord in batch) { - this.WriteLine($"{"LogRecord.TraceId:",-RightPaddingLength}{logRecord.TraceId}"); - this.WriteLine($"{"LogRecord.SpanId:",-RightPaddingLength}{logRecord.SpanId}"); this.WriteLine($"{"LogRecord.Timestamp:",-RightPaddingLength}{logRecord.Timestamp:yyyy-MM-ddTHH:mm:ss.fffffffZ}"); - this.WriteLine($"{"LogRecord.EventId:",-RightPaddingLength}{logRecord.EventId.Id}"); - this.WriteLine($"{"LogRecord.EventName:",-RightPaddingLength}{logRecord.EventId.Name}"); + + if (logRecord.TraceId != default) + { + this.WriteLine($"{"LogRecord.TraceId:",-RightPaddingLength}{logRecord.TraceId}"); + this.WriteLine($"{"LogRecord.SpanId:",-RightPaddingLength}{logRecord.SpanId}"); + this.WriteLine($"{"LogRecord.TraceFlags:",-RightPaddingLength}{logRecord.TraceFlags}"); + } + this.WriteLine($"{"LogRecord.CategoryName:",-RightPaddingLength}{logRecord.CategoryName}"); this.WriteLine($"{"LogRecord.LogLevel:",-RightPaddingLength}{logRecord.LogLevel}"); - this.WriteLine($"{"LogRecord.TraceFlags:",-RightPaddingLength}{logRecord.TraceFlags}"); if (logRecord.FormattedMessage != null) { this.WriteLine($"{"LogRecord.FormattedMessage:",-RightPaddingLength}{logRecord.FormattedMessage}"); @@ -59,6 +62,15 @@ public override ExportResult Export(in Batch batch) } } + if (logRecord.EventId != default) + { + this.WriteLine($"{"LogRecord.EventId:",-RightPaddingLength}{logRecord.EventId.Id}"); + if (string.IsNullOrEmpty(logRecord.EventId.Name)) + { + this.WriteLine($"{"LogRecord.EventName:",-RightPaddingLength}{logRecord.EventId.Name}"); + } + } + if (logRecord.Exception is { }) { this.WriteLine($"{"LogRecord.Exception:",-RightPaddingLength}{logRecord.Exception?.Message}"); @@ -84,10 +96,10 @@ void ProcessScope(LogRecordScope scope, ConsoleLogRecordExporter exporter) var resource = this.ParentProvider.GetResource(); if (resource != Resource.Empty) { - this.WriteLine("Resource associated with LogRecord:"); + this.WriteLine("\nResource associated with LogRecord:"); foreach (var resourceAttribute in resource.Attributes) { - this.WriteLine($" {resourceAttribute.Key}: {resourceAttribute.Value}"); + this.WriteLine($"{resourceAttribute.Key}: {resourceAttribute.Value}"); } }