go.mod+build: update btclog dep

This commit is contained in:
Elle Mouton
2024-11-25 12:05:44 +02:00
parent c8cfa59316
commit b98fc168ec
5 changed files with 33 additions and 8 deletions

View File

@@ -67,11 +67,10 @@ func DefaultLogConfig() *LogConfig {
// config struct translates to.
func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption {
opts := []btclog.HandlerOption{
// The default skip depth used by the logging library is 6 but
// since we wrap the logging handlers with another level of
// abstraction with the handlerSet, we increase the skip depth
// to 7 here.
btclog.WithCallSiteSkipDepth(7),
// We wrap the logger provided by the logging library with
// another layer of abstraction with the handlerSet, and so we
// need to increase the default skip depth by 1.
btclog.WithCallSiteSkipDepth(btclog.DefaultSkipDepth + 1),
}
if cfg.NoTimestamps {

View File

@@ -108,6 +108,19 @@ func (h *handlerSet) Level() btclogv1.Level {
return h.level
}
// WithPrefix returns a copy of the Handler but with the given string prefixed
// to each log message.
//
// NOTE: this is part of the btclog.Handler interface.
func (h *handlerSet) WithPrefix(prefix string) btclog.Handler {
newSet := &handlerSet{set: make([]btclog.Handler, len(h.set))}
for i, handler := range h.set {
newSet.set[i] = handler.WithPrefix(prefix)
}
return newSet
}
// A compile-time check to ensure that handlerSet implements btclog.Handler.
var _ btclog.Handler = (*handlerSet)(nil)

View File

@@ -163,5 +163,18 @@ func (p *PrefixLog) SetLevel(level btclogv1.Level) {
p.log.SetLevel(level)
}
// SubSystem returns a copy of the logger but with the new subsystem tag. Any
// previously set prefix will be overridden with an empty string.
func (p *PrefixLog) SubSystem(tag string) btclog.Logger {
return p.log.SubSystem(tag)
}
// WithPrefix returns a copy of the logger but with the given string prefixed to
// each log message. Note that the subsystem of the original logger is kept but
// any existing prefix is overridden.
func (p *PrefixLog) WithPrefix(prefix string) btclog.Logger {
return p.log.WithPrefix(prefix)
}
// Assert that PrefixLog fulfills the btclog.Logger interface.
var _ btclog.Logger = &PrefixLog{}