From ff722938725937c866e9dd0bf43cd457e81ea3ac Mon Sep 17 00:00:00 2001 From: Paul Larsen Date: Sun, 22 Dec 2024 11:33:42 +0100 Subject: [PATCH] Add component name to each instantiated slog instance --- ext/dispatcher.go | 6 ++---- ext/updater.go | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/ext/dispatcher.go b/ext/dispatcher.go index e427a6a..5cd0c84 100644 --- a/ext/dispatcher.go +++ b/ext/dispatcher.go @@ -77,7 +77,6 @@ type Dispatcher struct { // If nil, the error goes to the logger. UnhandledErrFunc ErrorFunc // Logger specifies an optional logger for unexpected behavior from handlers. - // If nil, logging is done via the log package's standard logger. Logger *slog.Logger // handlers represents all available handlers. @@ -110,8 +109,7 @@ type DispatcherOpts struct { // dispatcher actions. // If nil, the error goes to the logger. UnhandledErrFunc ErrorFunc - // logger specifies an optional logger for unexpected behavior from handlers. - // If nil, logging is done via the log package's standard logger. + // Logger specifies an optional logger for unexpected behavior from handlers. Logger *slog.Logger // MaxRoutines is used to decide how to limit the number of goroutines spawned by the dispatcher. @@ -157,7 +155,7 @@ func NewDispatcher(opts *DispatcherOpts) *Dispatcher { } return &Dispatcher{ - Logger: logger, + Logger: logger.With("component", "dispatcher"), Processor: processor, Error: errHandler, Panic: panicHandler, diff --git a/ext/updater.go b/ext/updater.go index 4812f9b..86efd9e 100644 --- a/ext/updater.go +++ b/ext/updater.go @@ -35,7 +35,6 @@ type Updater struct { // If nil, the error goes to the logger. UnhandledErrFunc ErrorFunc // Logger specifies an optional logger for unexpected behavior from handlers. - // If nil, logging is done via the log package's standard logger. Logger *slog.Logger // stopIdling is the channel that blocks the main thread from exiting, to keep the bots running. @@ -54,7 +53,6 @@ type UpdaterOpts struct { // If nil, the error goes to the logger. UnhandledErrFunc ErrorFunc // Logger specifies an optional logger for unexpected behavior from handlers. - // If nil, logging is done via the log package's standard logger. Logger *slog.Logger } @@ -71,10 +69,10 @@ func NewUpdater(dispatcher UpdateDispatcher, opts *UpdaterOpts) *Updater { return &Updater{ Dispatcher: dispatcher, UnhandledErrFunc: unhandledErrFunc, - Logger: logger, + Logger: logger.With("component", "updater"), botMapping: botMapping{ errFunc: unhandledErrFunc, - logger: logger, + logger: logger.With("component", "botmapping"), }, } }