-
Notifications
You must be signed in to change notification settings - Fork 223
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
Logging improvements #941
Logging improvements #941
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,33 @@ package tele | |
|
||
import ( | ||
logging "github.com/ipfs/go-log/v2" | ||
"github.com/libp2p/go-libp2p-kad-dht/v2/kadt" | ||
"go.uber.org/zap/exp/zapslog" | ||
"golang.org/x/exp/slog" | ||
) | ||
|
||
func DefaultLogger(system string) *slog.Logger { | ||
return slog.New(zapslog.NewHandler(logging.Logger(system).Desugar().Core())) | ||
func DefaultLogger(name string) *slog.Logger { | ||
return slog.New(zapslog.NewHandler(logging.Logger(name).Desugar().Core())) | ||
} | ||
|
||
// Attributes that can be used with logging or tracing | ||
const ( | ||
AttrKeyError = "error" | ||
AttrKeyPeerID = "peer_id" | ||
AttrKeyKey = "key" | ||
AttrKeyCacheHit = "hit" | ||
AttrKeyInEvent = "in_event" | ||
AttrKeyOutEvent = "out_event" | ||
Comment on lines
+16
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If they are only used in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They're designed to be used wherever we need them, such as logging an attribute There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all good 👍 |
||
) | ||
|
||
func LogAttrError(err error) slog.Attr { | ||
return slog.Attr{Key: AttrKeyError, Value: slog.AnyValue(err)} | ||
} | ||
|
||
func LogAttrPeerID(id kadt.PeerID) slog.Attr { | ||
return slog.String(AttrKeyPeerID, id.String()) | ||
} | ||
|
||
func LogAttrKey(kk kadt.Key) slog.Attr { | ||
return slog.String(AttrKeyKey, kk.HexString()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not necessary, but now that we have helper methods for logging error messages we could use the more performant LogAttrs method here. Error logs shouldn't live in the hot path anyway so feel free to ignore.