aboutsummaryrefslogtreecommitdiffstats
path: root/log
diff options
context:
space:
mode:
Diffstat (limited to 'log')
-rw-r--r--log/format.go2
-rw-r--r--log/logger.go17
-rw-r--r--log/root.go21
3 files changed, 25 insertions, 15 deletions
diff --git a/log/format.go b/log/format.go
index fb1ea1a7b..bed32bd2d 100644
--- a/log/format.go
+++ b/log/format.go
@@ -15,7 +15,7 @@ import (
const (
timeFormat = "2006-01-02T15:04:05-0700"
- termTimeFormat = "01-02|15:04:05"
+ termTimeFormat = "01-02|15:04:05.999999"
floatFormat = 'f'
termMsgJust = 40
)
diff --git a/log/logger.go b/log/logger.go
index a2fe6dc58..438aa548f 100644
--- a/log/logger.go
+++ b/log/logger.go
@@ -12,6 +12,7 @@ const timeKey = "t"
const lvlKey = "lvl"
const msgKey = "msg"
const errorKey = "LOG15_ERROR"
+const skipLevel = 2
type Lvl int
@@ -127,13 +128,13 @@ type logger struct {
h *swapHandler
}
-func (l *logger) write(msg string, lvl Lvl, ctx []interface{}) {
+func (l *logger) write(msg string, lvl Lvl, ctx []interface{}, skip int) {
l.h.Log(&Record{
Time: time.Now(),
Lvl: lvl,
Msg: msg,
Ctx: newContext(l.ctx, ctx),
- Call: stack.Caller(2),
+ Call: stack.Caller(skip),
KeyNames: RecordKeyNames{
Time: timeKey,
Msg: msgKey,
@@ -157,27 +158,27 @@ func newContext(prefix []interface{}, suffix []interface{}) []interface{} {
}
func (l *logger) Trace(msg string, ctx ...interface{}) {
- l.write(msg, LvlTrace, ctx)
+ l.write(msg, LvlTrace, ctx, skipLevel)
}
func (l *logger) Debug(msg string, ctx ...interface{}) {
- l.write(msg, LvlDebug, ctx)
+ l.write(msg, LvlDebug, ctx, skipLevel)
}
func (l *logger) Info(msg string, ctx ...interface{}) {
- l.write(msg, LvlInfo, ctx)
+ l.write(msg, LvlInfo, ctx, skipLevel)
}
func (l *logger) Warn(msg string, ctx ...interface{}) {
- l.write(msg, LvlWarn, ctx)
+ l.write(msg, LvlWarn, ctx, skipLevel)
}
func (l *logger) Error(msg string, ctx ...interface{}) {
- l.write(msg, LvlError, ctx)
+ l.write(msg, LvlError, ctx, skipLevel)
}
func (l *logger) Crit(msg string, ctx ...interface{}) {
- l.write(msg, LvlCrit, ctx)
+ l.write(msg, LvlCrit, ctx, skipLevel)
os.Exit(1)
}
diff --git a/log/root.go b/log/root.go
index 71b8cef6d..9fb4c5ae0 100644
--- a/log/root.go
+++ b/log/root.go
@@ -31,31 +31,40 @@ func Root() Logger {
// Trace is a convenient alias for Root().Trace
func Trace(msg string, ctx ...interface{}) {
- root.write(msg, LvlTrace, ctx)
+ root.write(msg, LvlTrace, ctx, skipLevel)
}
// Debug is a convenient alias for Root().Debug
func Debug(msg string, ctx ...interface{}) {
- root.write(msg, LvlDebug, ctx)
+ root.write(msg, LvlDebug, ctx, skipLevel)
}
// Info is a convenient alias for Root().Info
func Info(msg string, ctx ...interface{}) {
- root.write(msg, LvlInfo, ctx)
+ root.write(msg, LvlInfo, ctx, skipLevel)
}
// Warn is a convenient alias for Root().Warn
func Warn(msg string, ctx ...interface{}) {
- root.write(msg, LvlWarn, ctx)
+ root.write(msg, LvlWarn, ctx, skipLevel)
}
// Error is a convenient alias for Root().Error
func Error(msg string, ctx ...interface{}) {
- root.write(msg, LvlError, ctx)
+ root.write(msg, LvlError, ctx, skipLevel)
}
// Crit is a convenient alias for Root().Crit
func Crit(msg string, ctx ...interface{}) {
- root.write(msg, LvlCrit, ctx)
+ root.write(msg, LvlCrit, ctx, skipLevel)
os.Exit(1)
}
+
+// Output is a convenient alias for write, allowing for the modification of
+// the calldepth (number of stack frames to skip).
+// calldepth influences the reported line number of the log message.
+// A calldepth of zero reports the immediate caller of Output.
+// Non-zero calldepth skips as many stack frames.
+func Output(msg string, lvl Lvl, calldepth int, ctx ...interface{}) {
+ root.write(msg, lvl, ctx, calldepth+skipLevel)
+}