Skip to content

Commit

Permalink
ConsoleExporter Log minor cosmetic improvement. (#3211)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Apr 20, 2022
1 parent 1916cc9 commit 50baa25
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/OpenTelemetry.Exporter.Console/ConsoleLogRecordExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace OpenTelemetry.Exporter
{
public class ConsoleLogRecordExporter : ConsoleExporter<LogRecord>
{
private const int RightPaddingLength = 30;
private const int RightPaddingLength = 35;

public ConsoleLogRecordExporter(ConsoleExporterOptions options)
: base(options)
Expand All @@ -33,14 +33,17 @@ public override ExportResult Export(in Batch<LogRecord> 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}");
Expand All @@ -59,6 +62,15 @@ public override ExportResult Export(in Batch<LogRecord> 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}");
Expand All @@ -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}");
}
}

Expand Down

0 comments on commit 50baa25

Please sign in to comment.