|
|
@ -2,6 +2,7 @@ package log |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
|
|
|
|
"os" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/go-stack/stack" |
|
|
|
"github.com/go-stack/stack" |
|
|
@ -20,11 +21,14 @@ const ( |
|
|
|
LvlWarn |
|
|
|
LvlWarn |
|
|
|
LvlInfo |
|
|
|
LvlInfo |
|
|
|
LvlDebug |
|
|
|
LvlDebug |
|
|
|
|
|
|
|
LvlTrace |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Returns the name of a Lvl
|
|
|
|
// Returns the name of a Lvl
|
|
|
|
func (l Lvl) String() string { |
|
|
|
func (l Lvl) String() string { |
|
|
|
switch l { |
|
|
|
switch l { |
|
|
|
|
|
|
|
case LvlTrace: |
|
|
|
|
|
|
|
return "trce" |
|
|
|
case LvlDebug: |
|
|
|
case LvlDebug: |
|
|
|
return "dbug" |
|
|
|
return "dbug" |
|
|
|
case LvlInfo: |
|
|
|
case LvlInfo: |
|
|
@ -44,6 +48,8 @@ func (l Lvl) String() string { |
|
|
|
// Useful for parsing command line args and configuration files.
|
|
|
|
// Useful for parsing command line args and configuration files.
|
|
|
|
func LvlFromString(lvlString string) (Lvl, error) { |
|
|
|
func LvlFromString(lvlString string) (Lvl, error) { |
|
|
|
switch lvlString { |
|
|
|
switch lvlString { |
|
|
|
|
|
|
|
case "trace", "trce": |
|
|
|
|
|
|
|
return LvlTrace, nil |
|
|
|
case "debug", "dbug": |
|
|
|
case "debug", "dbug": |
|
|
|
return LvlDebug, nil |
|
|
|
return LvlDebug, nil |
|
|
|
case "info": |
|
|
|
case "info": |
|
|
@ -87,6 +93,7 @@ type Logger interface { |
|
|
|
SetHandler(h Handler) |
|
|
|
SetHandler(h Handler) |
|
|
|
|
|
|
|
|
|
|
|
// Log a message at the given level with context key/value pairs
|
|
|
|
// Log a message at the given level with context key/value pairs
|
|
|
|
|
|
|
|
Trace(msg string, ctx ...interface{}) |
|
|
|
Debug(msg string, ctx ...interface{}) |
|
|
|
Debug(msg string, ctx ...interface{}) |
|
|
|
Info(msg string, ctx ...interface{}) |
|
|
|
Info(msg string, ctx ...interface{}) |
|
|
|
Warn(msg string, ctx ...interface{}) |
|
|
|
Warn(msg string, ctx ...interface{}) |
|
|
@ -128,6 +135,10 @@ func newContext(prefix []interface{}, suffix []interface{}) []interface{} { |
|
|
|
return newCtx |
|
|
|
return newCtx |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (l *logger) Trace(msg string, ctx ...interface{}) { |
|
|
|
|
|
|
|
l.write(msg, LvlTrace, ctx) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (l *logger) Debug(msg string, ctx ...interface{}) { |
|
|
|
func (l *logger) Debug(msg string, ctx ...interface{}) { |
|
|
|
l.write(msg, LvlDebug, ctx) |
|
|
|
l.write(msg, LvlDebug, ctx) |
|
|
|
} |
|
|
|
} |
|
|
@ -146,6 +157,7 @@ func (l *logger) Error(msg string, ctx ...interface{}) { |
|
|
|
|
|
|
|
|
|
|
|
func (l *logger) Crit(msg string, ctx ...interface{}) { |
|
|
|
func (l *logger) Crit(msg string, ctx ...interface{}) { |
|
|
|
l.write(msg, LvlCrit, ctx) |
|
|
|
l.write(msg, LvlCrit, ctx) |
|
|
|
|
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (l *logger) GetHandler() Handler { |
|
|
|
func (l *logger) GetHandler() Handler { |
|
|
|