Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make logging prettier #45

Merged
merged 1 commit into from
Aug 24, 2018
Merged
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
8 changes: 6 additions & 2 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,17 @@ func (el *eventLogger) Event(ctx context.Context, event string, metadata ...Logg
accum["system"] = e.system
accum["time"] = FormatRFC3339(time.Now())

out, err := json.Marshal(accum)
var buf bytes.Buffer
encoder := json.NewEncoder(&buf)
encoder.SetEscapeHTML(false)
encoder.SetIndent("", " ")
err = encoder.Encode(accum)
if err != nil {
el.Errorf("ERROR FORMATTING EVENT ENTRY: %s", err)
return
}

writer.WriterGroup.Write(append(out, '\n'))
writer.WriterGroup.Write(buf.Bytes())
}

// DEPRECATED
Expand Down
24 changes: 21 additions & 3 deletions tracer/recorder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package loggabletracer

import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"os"
Expand Down Expand Up @@ -65,22 +67,38 @@ func (r *LoggableSpanRecorder) RecordSpan(span RawSpan) {
}
}

tags := make(map[string]interface{}, len(span.Tags))
for k, v := range span.Tags {
switch vt := v.(type) {
case bool, string, int, int8, int16, int32, int64, uint, uint8, uint16, uint64:
tags[k] = v
case []byte:
base64.StdEncoding.EncodeToString(vt)
default:
tags[k] = fmt.Sprint(v)
}
}

spanlog := &LoggableSpan{
TraceID: span.Context.TraceID,
SpanID: span.Context.SpanID,
ParentSpanID: span.ParentSpanID,
Operation: span.Operation,
Start: span.Start,
Duration: span.Duration,
Tags: span.Tags,
Tags: tags,
Logs: sl,
}

out, err := json.Marshal(spanlog)
var buf bytes.Buffer
encoder := json.NewEncoder(&buf)
encoder.SetEscapeHTML(false)
encoder.SetIndent("", " ")
err := encoder.Encode(spanlog)
if err != nil {
fmt.Fprintf(os.Stderr, "ERROR FORMATTING SPAN ENTRY: %s\n", err)
return
}

writer.WriterGroup.Write(append(out, '\n'))
writer.WriterGroup.Write(buf.Bytes())
}