Skip to content

Commit

Permalink
Show trace when level is debugC
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoConstantine committed Jan 12, 2025
1 parent 991383c commit 64c4aa1
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions pkg/logging/outputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,18 +344,22 @@ func (o *ConsoleOutput) Write(e LogEntry) error {
defer o.mu.Unlock()

// Format basic log info
timestamp := time.Unix(0, e.Time).Format("2006-01-02 15:04:05.000")
timestamp := time.Unix(0, e.Time).Format(time.RFC3339)

var levelColor, resetColor string
if o.color {
levelColor = getSeverityColor(e.Severity)
resetColor = "\033[0m"
}

// Create a more concise trace ID
traceID := e.TraceID
if len(traceID) > 8 {
traceID = traceID[:8]
traceDisplay := "traceId=-" // Default when no trace ID is present
if e.TraceID != "" {
// Truncate long trace IDs to 8 characters for readability
displayID := e.TraceID
if len(displayID) > 8 {
displayID = displayID[:8]
}
traceDisplay = fmt.Sprintf("traceId=%s", displayID)
}

// Format the base message
Expand All @@ -364,7 +368,7 @@ func (o *ConsoleOutput) Write(e LogEntry) error {
levelColor,
e.Severity,
resetColor,
traceID,
traceDisplay,
e.File,
e.Line,
e.Message,
Expand All @@ -380,11 +384,13 @@ func (o *ConsoleOutput) Write(e LogEntry) error {
return err
}

if spans, ok := e.Fields["spans"]; ok && spans != nil {
if spanSlice, ok := spans.([]*core.Span); ok && len(spanSlice) > 0 {
spanInfo := formatSpans(spanSlice)
if _, err := fmt.Fprintln(o.writer, spanInfo); err != nil {
return err
if e.Severity <= DEBUG {
if spans, ok := e.Fields["spans"]; ok && spans != nil {
if spanSlice, ok := spans.([]*core.Span); ok && len(spanSlice) > 0 {
spanInfo := formatSpans(spanSlice)
if _, err := fmt.Fprintln(o.writer, spanInfo); err != nil {
return err
}
}
}
}
Expand Down

0 comments on commit 64c4aa1

Please sign in to comment.