diff options
Diffstat (limited to 'internal/server.go')
-rw-r--r-- | internal/server.go | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/internal/server.go b/internal/server.go index a95efc1..21d1a7f 100644 --- a/internal/server.go +++ b/internal/server.go @@ -6,20 +6,18 @@ import ( "strings" "sync" + "github.com/go-kit/log" + "github.com/go-kit/log/level" "tildegit.org/tjp/sliderule/logging" ) -type logger interface { - Log(keyvals ...any) error -} - type Server struct { Ctx context.Context Cancel context.CancelFunc Wg *sync.WaitGroup Listener net.Listener HandleConn connHandler - ErrorLog logger + ErrorLog logging.Logger Host string NetworkAddr net.Addr } @@ -31,7 +29,7 @@ func NewServer( hostname string, network string, address string, - errorLog logger, + baseLog logging.Logger, handleConn connHandler, ) (Server, error) { listener, err := net.Listen(network, address) @@ -42,10 +40,13 @@ func NewServer( networkAddr := listener.Addr() ctx, cancel := context.WithCancel(ctx) - debuglog, infolog, warnlog, errlog := logging.DefaultLoggers() - ctx = context.WithValue(ctx, "debuglog", debuglog) - ctx = context.WithValue(ctx, "infolog", infolog) - ctx = context.WithValue(ctx, "warnlog", warnlog) + if baseLog == nil { + baseLog = log.NewNopLogger() + } + errlog := level.Error(baseLog) + ctx = context.WithValue(ctx, "debuglog", level.Debug(baseLog)) + ctx = context.WithValue(ctx, "infolog", level.Info(baseLog)) + ctx = context.WithValue(ctx, "warnlog", level.Warn(baseLog)) ctx = context.WithValue(ctx, "errlog", errlog) return Server{ @@ -54,7 +55,7 @@ func NewServer( Wg: &sync.WaitGroup{}, Listener: listener, HandleConn: handleConn, - ErrorLog: errorLog, + ErrorLog: errlog, Host: hostname, NetworkAddr: networkAddr, }, nil |