vendor: update ln
This commit is contained in:
parent
c434bafce5
commit
834422055d
|
@ -134,3 +134,5 @@ da118f7b8e5954f39d0d2130ab35d4bf0e3cb344 golang.org/x/net/context
|
||||||
737072b4e32b7a5018b4a7125da8d12de90e8045 github.com/mattn/go-runewidth
|
737072b4e32b7a5018b4a7125da8d12de90e8045 github.com/mattn/go-runewidth
|
||||||
44e365d423f4f06769182abfeeae2b91be9d529b github.com/olekukonko/tablewriter
|
44e365d423f4f06769182abfeeae2b91be9d529b github.com/olekukonko/tablewriter
|
||||||
4e1c5567d7c2dd59fa4c7c83d34c2f3528b025d6 github.com/oxtoacart/bpool
|
4e1c5567d7c2dd59fa4c7c83d34c2f3528b025d6 github.com/oxtoacart/bpool
|
||||||
|
a3b3ca73af22dd09dfac218f586a8f42c681298d github.com/Xe/ln
|
||||||
|
c605e284fe17294bda444b34710735b29d1a9d90 github.com/pkg/errors
|
||||||
|
|
|
@ -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
|
|
@ -1,7 +1,6 @@
|
||||||
package ln
|
package ln
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -30,14 +29,28 @@ func init() {
|
||||||
DefaultLogger = &Logger{
|
DefaultLogger = &Logger{
|
||||||
Filters: defaultFilters,
|
Filters: defaultFilters,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// F is a key-value mapping for structured data.
|
// F is a key-value mapping for structured data.
|
||||||
type F map[string]interface{}
|
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 {
|
type Fer interface {
|
||||||
F() map[string]interface{}
|
F() F
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event represents an event
|
// Event represents an event
|
||||||
|
@ -48,8 +61,7 @@ type Event struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log is the generic logging method.
|
// Log is the generic logging method.
|
||||||
func (l *Logger) Log(xs ...interface{}) {
|
func (l *Logger) Log(xs ...Fer) {
|
||||||
var bits []interface{}
|
|
||||||
event := Event{Time: time.Now()}
|
event := Event{Time: time.Now()}
|
||||||
|
|
||||||
addF := func(bf F) {
|
addF := func(bf F) {
|
||||||
|
@ -62,18 +74,9 @@ func (l *Logger) Log(xs ...interface{}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assemble the event
|
for _, f := range xs {
|
||||||
for _, b := range xs {
|
addF(f.F())
|
||||||
if bf, ok := b.(F); ok {
|
|
||||||
addF(bf)
|
|
||||||
} else if fer, ok := b.(Fer); ok {
|
|
||||||
addF(F(fer.F()))
|
|
||||||
} else {
|
|
||||||
bits = append(bits, b)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
event.Message = fmt.Sprint(bits...)
|
|
||||||
|
|
||||||
if os.Getenv("LN_DEBUG_ALL_EVENTS") == "1" {
|
if os.Getenv("LN_DEBUG_ALL_EVENTS") == "1" {
|
||||||
frame := callersFrame()
|
frame := callersFrame()
|
||||||
|
@ -97,7 +100,7 @@ func (l *Logger) filter(e Event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error logs an error and information about the context of said error.
|
// 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{}
|
data := F{}
|
||||||
frame := callersFrame()
|
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.
|
// 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...)
|
l.Log(xs...)
|
||||||
|
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -126,16 +154,21 @@ func (l *Logger) Fatal(xs ...interface{}) {
|
||||||
// Default Implementation
|
// Default Implementation
|
||||||
|
|
||||||
// Log is the generic logging method.
|
// Log is the generic logging method.
|
||||||
func Log(xs ...interface{}) {
|
func Log(xs ...Fer) {
|
||||||
DefaultLogger.Log(xs...)
|
DefaultLogger.Log(xs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error logs an error and information about the context of said error.
|
// 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...)
|
DefaultLogger.Error(err, xs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fatal logs this set of values, then exits with status code 1.
|
// Fatal logs this set of values, then exits with status code 1.
|
||||||
func Fatal(xs ...interface{}) {
|
func Fatal(xs ...Fer) {
|
||||||
DefaultLogger.Fatal(xs...)
|
DefaultLogger.Fatal(xs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FatalErr combines Fatal and Error.
|
||||||
|
func FatalErr(err error, xs ...Fer) {
|
||||||
|
DefaultLogger.FatalErr(err, xs...)
|
||||||
|
}
|
||||||
|
|
|
@ -79,6 +79,14 @@ func (f Frame) Format(s fmt.State, verb rune) {
|
||||||
// StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
|
// StackTrace is stack of Frames from innermost (newest) to outermost (oldest).
|
||||||
type StackTrace []Frame
|
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) {
|
func (st StackTrace) Format(s fmt.State, verb rune) {
|
||||||
switch verb {
|
switch verb {
|
||||||
case 'v':
|
case 'v':
|
||||||
|
|
Loading…
Reference in New Issue