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

swarm/api: update log.Output to report meaningful log line #720

Merged
merged 1 commit into from
Jun 15, 2018
Merged
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
5 changes: 3 additions & 2 deletions swarm/api/http/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/swarm/api"
l "github.com/ethereum/go-ethereum/swarm/log"
)

//templateMap holds a mapping of an HTTP error code to a template
Expand Down Expand Up @@ -145,9 +146,9 @@ func Respond(w http.ResponseWriter, req *Request, msg string, code int) {
additionalMessage := ValidateCaseErrors(req)
switch code {
case http.StatusInternalServerError:
log.Output(msg, log.LvlError, 3, "ruid", req.ruid, "code", code)
log.Output(msg, log.LvlError, l.CallDepth, "ruid", req.ruid, "code", code)
default:
log.Output(msg, log.LvlDebug, 3, "ruid", req.ruid, "code", code)
log.Output(msg, log.LvlDebug, l.CallDepth, "ruid", req.ruid, "code", code)
}

if code >= 400 {
Expand Down
18 changes: 12 additions & 6 deletions swarm/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,44 @@ import (
"github.com/ethereum/go-ethereum/metrics"
)

const (
// CallDepth is set to 1 in order to influence to reported line number of
// the log message with 1 skipped stack frame of calling l.Output()
CallDepth = 1
)

// Warn is a convenient alias for log.Warn with stats
func Warn(msg string, ctx ...interface{}) {
metrics.GetOrRegisterCounter("warn", nil).Inc(1)
l.Output(msg, l.LvlWarn, 3, ctx...)
l.Output(msg, l.LvlWarn, CallDepth, ctx...)
}

// Error is a convenient alias for log.Error with stats
func Error(msg string, ctx ...interface{}) {
metrics.GetOrRegisterCounter("error", nil).Inc(1)
l.Output(msg, l.LvlError, 3, ctx...)
l.Output(msg, l.LvlError, CallDepth, ctx...)
}

// Crit is a convenient alias for log.Crit with stats
func Crit(msg string, ctx ...interface{}) {
metrics.GetOrRegisterCounter("crit", nil).Inc(1)
l.Output(msg, l.LvlCrit, 3, ctx...)
l.Output(msg, l.LvlCrit, CallDepth, ctx...)
}

// Info is a convenient alias for log.Info with stats
func Info(msg string, ctx ...interface{}) {
metrics.GetOrRegisterCounter("info", nil).Inc(1)
l.Output(msg, l.LvlInfo, 3, ctx...)
l.Output(msg, l.LvlInfo, CallDepth, ctx...)
}

// Debug is a convenient alias for log.Debug with stats
func Debug(msg string, ctx ...interface{}) {
metrics.GetOrRegisterCounter("debug", nil).Inc(1)
l.Output(msg, l.LvlDebug, 3, ctx...)
l.Output(msg, l.LvlDebug, CallDepth, ctx...)
}

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