Created
July 20, 2018 18:04
-
-
Save maplebed/631b994aa32638d10fc578927efb96ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package log | |
| import ( | |
| "io" | |
| libhoney "github.com/honeycombio/libhoney" | |
| ) | |
| type hnyLogger struct { | |
| } | |
| // NewJSONLogger returns a Logger that encodes keyvals to the Writer as a | |
| // single JSON object. Each log event produces no more than one call to | |
| // w.Write. The passed Writer must be safe for concurrent use by multiple | |
| // goroutines if the returned Logger will be used concurrently. | |
| func NewHoneycombLogger(w io.Writer) Logger { | |
| return &hnyLogger{} | |
| } | |
| func (l *jsonLogger) Log(keyvals ...interface{}) error { | |
| ev := libhoney.NewEvent() | |
| defer ev.Send() | |
| n := (len(keyvals) + 1) / 2 // +1 to handle case when len is odd | |
| m := make(map[string]interface{}, n) | |
| for i := 0; i < len(keyvals); i += 2 { | |
| k := keyvals[i] | |
| var v interface{} = ErrMissingValue | |
| if i+1 < len(keyvals) { | |
| v = keyvals[i+1] | |
| } | |
| ev.AddField(k, v) | |
| } | |
| return nil | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment