From b98fc168ecaf3d0d06806ce435fbddaee748fb34 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Mon, 25 Nov 2024 12:05:44 +0200 Subject: [PATCH] go.mod+build: update btclog dep --- build/config.go | 9 ++++----- build/handler_sets.go | 13 +++++++++++++ build/prefix_log.go | 13 +++++++++++++ go.mod | 2 +- go.sum | 4 ++-- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/build/config.go b/build/config.go index fd3b01a94..87b9ab9ae 100644 --- a/build/config.go +++ b/build/config.go @@ -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 { diff --git a/build/handler_sets.go b/build/handler_sets.go index d9786a858..485aca2d6 100644 --- a/build/handler_sets.go +++ b/build/handler_sets.go @@ -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) diff --git a/build/prefix_log.go b/build/prefix_log.go index 3db114ffc..22f4318ef 100644 --- a/build/prefix_log.go +++ b/build/prefix_log.go @@ -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{} diff --git a/go.mod b/go.mod index d0ff97ac7..6ca886630 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/btcsuite/btcd/btcutil/psbt v1.1.8 github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c - github.com/btcsuite/btclog/v2 v2.0.0-20241017175713-3428138b75c7 + github.com/btcsuite/btclog/v2 v2.0.0 github.com/btcsuite/btcwallet v0.16.10-0.20241113134707-b4ff60753aaa github.com/btcsuite/btcwallet/wallet/txauthor v1.3.5 github.com/btcsuite/btcwallet/wallet/txrules v1.2.2 diff --git a/go.sum b/go.sum index 2ea42fd8c..aa04dc5fc 100644 --- a/go.sum +++ b/go.sum @@ -92,8 +92,8 @@ github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0/go.mod h1:7SFka0XMvUgj3hfZtyd github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c h1:4HxD1lBUGUddhzgaNgrCPsFWd7cGYNpeFUgd9ZIgyM0= github.com/btcsuite/btclog v0.0.0-20241003133417-09c4e92e319c/go.mod h1:w7xnGOhwT3lmrS4H3b/D1XAXxvh+tbhUm8xeHN2y3TQ= -github.com/btcsuite/btclog/v2 v2.0.0-20241017175713-3428138b75c7 h1:3Ct3zN3VCEKVm5nceWBBEKczc+jvTfVyOEG71ob2Yuc= -github.com/btcsuite/btclog/v2 v2.0.0-20241017175713-3428138b75c7/go.mod h1:XItGUfVOxotJL8kkuk2Hj3EVow5KCugXl3wWfQ6K0AE= +github.com/btcsuite/btclog/v2 v2.0.0 h1:ZfOBItEeLWfU0voi88K72j8vtxP4/dHhxRFf2bxZkVo= +github.com/btcsuite/btclog/v2 v2.0.0/go.mod h1:XItGUfVOxotJL8kkuk2Hj3EVow5KCugXl3wWfQ6K0AE= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcwallet v0.16.10-0.20241113134707-b4ff60753aaa h1:x7vYpwkPL5zeJEWPPaRunybH9ERRMGWeNf7x/0aU/38= github.com/btcsuite/btcwallet v0.16.10-0.20241113134707-b4ff60753aaa/go.mod h1:1HJXYbjJzgumlnxOC2+ViR1U+gnHWoOn7WeK5OfY1eU=