diff --git a/vendor-log b/vendor-log index 7593ef1..d484b89 100644 --- a/vendor-log +++ b/vendor-log @@ -134,3 +134,5 @@ da118f7b8e5954f39d0d2130ab35d4bf0e3cb344 golang.org/x/net/context 737072b4e32b7a5018b4a7125da8d12de90e8045 github.com/mattn/go-runewidth 44e365d423f4f06769182abfeeae2b91be9d529b github.com/olekukonko/tablewriter 4e1c5567d7c2dd59fa4c7c83d34c2f3528b025d6 github.com/oxtoacart/bpool +a3b3ca73af22dd09dfac218f586a8f42c681298d github.com/Xe/ln +c605e284fe17294bda444b34710735b29d1a9d90 github.com/pkg/errors diff --git a/vendor/github.com/Xe/ln/doc.go b/vendor/github.com/Xe/ln/doc.go new file mode 100644 index 0000000..ab81c3c --- /dev/null +++ b/vendor/github.com/Xe/ln/doc.go @@ -0,0 +1,25 @@ +/* +Package ln is the Natural Logger for Go + +`ln` provides a simple interface to logging, and metrics, and +obviates the need to utilize purpose built metrics packages, like +`go-metrics` for simple use cases. + +The design of `ln` centers around the idea of key-value pairs, which +can be interpreted on the fly, but "Filters" to do things such as +aggregated metrics, and report said metrics to, say Librato, or +statsd. + +"Filters" are like WSGI, or Rack Middleware. They are run "top down" +and can abort an emitted log's output at any time, or continue to let +it through the chain. However, the interface is slightly different +than that. Rather than encapsulating the chain with partial function +application, we utilize a simpler method, namely, each plugin defines +an `Apply` function, which takes as an argument the log event, and +performs the work of the plugin, only if the Plugin "Applies" to this +log event. + +If `Apply` returns `false`, the iteration through the rest of the +filters is aborted, and the log is dropped from further processing. +*/ +package ln diff --git a/vendor/github.com/Xe/ln/logger.go b/vendor/github.com/Xe/ln/logger.go index cdfe89e..47d8b5d 100644 --- a/vendor/github.com/Xe/ln/logger.go +++ b/vendor/github.com/Xe/ln/logger.go @@ -1,7 +1,6 @@ package ln import ( - "fmt" "os" "time" @@ -30,14 +29,28 @@ func init() { DefaultLogger = &Logger{ Filters: defaultFilters, } - } // F is a key-value mapping for structured data. type F map[string]interface{} +// Extend concatentates one F with one or many Fer instances. +func (f F) Extend(other ...Fer) { + for _, ff := range other { + for k, v := range ff.F() { + f[k] = v + } + } +} + +// F makes F an Fer +func (f F) F() F { + return f +} + +// Fer allows any type to add fields to the structured logging key->value pairs. type Fer interface { - F() map[string]interface{} + F() F } // Event represents an event @@ -48,8 +61,7 @@ type Event struct { } // Log is the generic logging method. -func (l *Logger) Log(xs ...interface{}) { - var bits []interface{} +func (l *Logger) Log(xs ...Fer) { event := Event{Time: time.Now()} addF := func(bf F) { @@ -62,19 +74,10 @@ func (l *Logger) Log(xs ...interface{}) { } } - // Assemble the event - for _, b := range xs { - if bf, ok := b.(F); ok { - addF(bf) - } else if fer, ok := b.(Fer); ok { - addF(F(fer.F())) - } else { - bits = append(bits, b) - } + for _, f := range xs { + addF(f.F()) } - event.Message = fmt.Sprint(bits...) - if os.Getenv("LN_DEBUG_ALL_EVENTS") == "1" { frame := callersFrame() if event.Data == nil { @@ -97,7 +100,7 @@ func (l *Logger) filter(e Event) { } // Error logs an error and information about the context of said error. -func (l *Logger) Error(err error, xs ...interface{}) { +func (l *Logger) Error(err error, xs ...Fer) { data := F{} frame := callersFrame() @@ -117,7 +120,32 @@ func (l *Logger) Error(err error, xs ...interface{}) { } // Fatal logs this set of values, then exits with status code 1. -func (l *Logger) Fatal(xs ...interface{}) { +func (l *Logger) Fatal(xs ...Fer) { + xs = append(xs, F{"fatal": true}) + + l.Log(xs...) + + os.Exit(1) +} + +// FatalErr combines Fatal and Error. +func (l *Logger) FatalErr(err error, xs ...Fer) { + xs = append(xs, F{"fatal": true}) + + data := F{} + frame := callersFrame() + + data["_lineno"] = frame.lineno + data["_function"] = frame.function + data["_filename"] = frame.filename + data["err"] = err + + cause := errors.Cause(err) + if cause != nil { + data["cause"] = cause.Error() + } + + xs = append(xs, data) l.Log(xs...) os.Exit(1) @@ -126,16 +154,21 @@ func (l *Logger) Fatal(xs ...interface{}) { // Default Implementation // Log is the generic logging method. -func Log(xs ...interface{}) { +func Log(xs ...Fer) { DefaultLogger.Log(xs...) } // Error logs an error and information about the context of said error. -func Error(err error, xs ...interface{}) { +func Error(err error, xs ...Fer) { DefaultLogger.Error(err, xs...) } // Fatal logs this set of values, then exits with status code 1. -func Fatal(xs ...interface{}) { +func Fatal(xs ...Fer) { DefaultLogger.Fatal(xs...) } + +// FatalErr combines Fatal and Error. +func FatalErr(err error, xs ...Fer) { + DefaultLogger.FatalErr(err, xs...) +} diff --git a/vendor/github.com/pkg/errors/stack.go b/vendor/github.com/pkg/errors/stack.go index 6b1f289..cbe3f3e 100644 --- a/vendor/github.com/pkg/errors/stack.go +++ b/vendor/github.com/pkg/errors/stack.go @@ -79,6 +79,14 @@ func (f Frame) Format(s fmt.State, verb rune) { // StackTrace is stack of Frames from innermost (newest) to outermost (oldest). type StackTrace []Frame +// Format formats the stack of Frames according to the fmt.Formatter interface. +// +// %s lists source files for each Frame in the stack +// %v lists the source file and line number for each Frame in the stack +// +// Format accepts flags that alter the printing of some verbs, as follows: +// +// %+v Prints filename, function, and line number for each Frame in the stack. func (st StackTrace) Format(s fmt.State, verb rune) { switch verb { case 'v':