Skip to content

Commit

Permalink
trim file path in p2p logger
Browse files Browse the repository at this point in the history
  • Loading branch information
cce committed Jun 28, 2024
1 parent 8b291b0 commit 4152b88
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion network/p2p/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package p2p

import (
"runtime"
"strings"

p2plogging "github.com/ipfs/go-log/v2"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -103,8 +104,11 @@ func (c *loggingCore) Write(e zapcore.Entry, fields []zapcore.Field) error {
}
}
event := c.log.WithFields(loggingFields).With("libp2p", e.LoggerName)
file := e.Caller.File
slash := strings.LastIndex(file, "/")
file = file[slash+1:]
event = event.WithFields(logrus.Fields{
"file": e.Caller.File,
"file": file,
"line": e.Caller.Line,
})
if function := runtime.FuncForPC(e.Caller.PC); function != nil {
Expand Down

0 comments on commit 4152b88

Please sign in to comment.