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

added trace level #112

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func TerminalFormat() Format {
color = 32
case LvlDebug:
color = 36
case LvlTrace:
color = 34
}

b := &bytes.Buffer{}
Expand Down
10 changes: 10 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ const (
LvlWarn
LvlInfo
LvlDebug
LvlTrace
)

// Returns the name of a Lvl
func (l Lvl) String() string {
switch l {
case LvlTrace:
return "trce"
case LvlDebug:
return "dbug"
case LvlInfo:
Expand All @@ -44,6 +47,8 @@ func (l Lvl) String() string {
// Useful for parsing command line args and configuration files.
func LvlFromString(lvlString string) (Lvl, error) {
switch lvlString {
case "trace", "trce":
return LvlTrace, nil
case "debug", "dbug":
return LvlDebug, nil
case "info":
Expand Down Expand Up @@ -87,6 +92,7 @@ type Logger interface {
SetHandler(h Handler)

// Log a message at the given level with context key/value pairs
Trace(msg string, ctx ...interface{})
Debug(msg string, ctx ...interface{})
Info(msg string, ctx ...interface{})
Warn(msg string, ctx ...interface{})
Expand Down Expand Up @@ -128,6 +134,10 @@ func newContext(prefix []interface{}, suffix []interface{}) []interface{} {
return newCtx
}

func (l *logger) Trace(msg string, ctx ...interface{}) {
l.write(msg, LvlTrace, ctx)
}

func (l *logger) Debug(msg string, ctx ...interface{}) {
l.write(msg, LvlDebug, ctx)
}
Expand Down
5 changes: 5 additions & 0 deletions root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ func Root() Logger {
// etc.) to keep the call depth the same for all paths to logger.write so
// runtime.Caller(2) always refers to the call site in client code.

// Trace is a convenient alias for Root().Trace
func Trace(msg string, ctx ...interface{}) {
root.write(msg, LvlTrace, ctx)
}

// Debug is a convenient alias for Root().Debug
func Debug(msg string, ctx ...interface{}) {
root.write(msg, LvlDebug, ctx)
Expand Down
2 changes: 2 additions & 0 deletions syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func sharedSyslog(fmtr Format, sysWr *syslog.Writer, err error) (Handler, error)
syslogFn = sysWr.Info
case LvlDebug:
syslogFn = sysWr.Debug
case LvlTrace:
syslogFn = sysWr.Debug // use debug since syslog does not provide a trace level
}

s := strings.TrimSpace(string(fmtr.Format(r)))
Expand Down