Skip to content
This repository was archived by the owner on Aug 2, 2021. It is now read-only.

Commit bb26ae1

Browse files
committed
swarm/api: update log.Output to report meaningful log line
1 parent 9d35ceb commit bb26ae1

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

swarm/api/http/error.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/ethereum/go-ethereum/log"
3232
"github.com/ethereum/go-ethereum/metrics"
3333
"github.com/ethereum/go-ethereum/swarm/api"
34+
l "github.com/ethereum/go-ethereum/swarm/log"
3435
)
3536

3637
//templateMap holds a mapping of an HTTP error code to a template
@@ -145,9 +146,9 @@ func Respond(w http.ResponseWriter, req *Request, msg string, code int) {
145146
additionalMessage := ValidateCaseErrors(req)
146147
switch code {
147148
case http.StatusInternalServerError:
148-
log.Output(msg, log.LvlError, 3, "ruid", req.ruid, "code", code)
149+
log.Output(msg, log.LvlError, l.CallDepth, "ruid", req.ruid, "code", code)
149150
default:
150-
log.Output(msg, log.LvlDebug, 3, "ruid", req.ruid, "code", code)
151+
log.Output(msg, log.LvlDebug, l.CallDepth, "ruid", req.ruid, "code", code)
151152
}
152153

153154
if code >= 400 {

swarm/log/log.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,44 @@ import (
55
"github.com/ethereum/go-ethereum/metrics"
66
)
77

8+
const (
9+
// CallDepth is set to 1 in order to influence to reported line number of
10+
// the log message with 1 skipped stack frame of calling l.Output()
11+
CallDepth = 1
12+
)
13+
814
// Warn is a convenient alias for log.Warn with stats
915
func Warn(msg string, ctx ...interface{}) {
1016
metrics.GetOrRegisterCounter("warn", nil).Inc(1)
11-
l.Output(msg, l.LvlWarn, 3, ctx...)
17+
l.Output(msg, l.LvlWarn, CallDepth, ctx...)
1218
}
1319

1420
// Error is a convenient alias for log.Error with stats
1521
func Error(msg string, ctx ...interface{}) {
1622
metrics.GetOrRegisterCounter("error", nil).Inc(1)
17-
l.Output(msg, l.LvlError, 3, ctx...)
23+
l.Output(msg, l.LvlError, CallDepth, ctx...)
1824
}
1925

2026
// Crit is a convenient alias for log.Crit with stats
2127
func Crit(msg string, ctx ...interface{}) {
2228
metrics.GetOrRegisterCounter("crit", nil).Inc(1)
23-
l.Output(msg, l.LvlCrit, 3, ctx...)
29+
l.Output(msg, l.LvlCrit, CallDepth, ctx...)
2430
}
2531

2632
// Info is a convenient alias for log.Info with stats
2733
func Info(msg string, ctx ...interface{}) {
2834
metrics.GetOrRegisterCounter("info", nil).Inc(1)
29-
l.Output(msg, l.LvlInfo, 3, ctx...)
35+
l.Output(msg, l.LvlInfo, CallDepth, ctx...)
3036
}
3137

3238
// Debug is a convenient alias for log.Debug with stats
3339
func Debug(msg string, ctx ...interface{}) {
3440
metrics.GetOrRegisterCounter("debug", nil).Inc(1)
35-
l.Output(msg, l.LvlDebug, 3, ctx...)
41+
l.Output(msg, l.LvlDebug, CallDepth, ctx...)
3642
}
3743

3844
// Trace is a convenient alias for log.Trace with stats
3945
func Trace(msg string, ctx ...interface{}) {
4046
metrics.GetOrRegisterCounter("trace", nil).Inc(1)
41-
l.Output(msg, l.LvlTrace, 3, ctx...)
47+
l.Output(msg, l.LvlTrace, CallDepth, ctx...)
4248
}

0 commit comments

Comments
 (0)