Skip to content

Commit

Permalink
Add component name to each instantiated slog instance
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSonOfLars committed Dec 22, 2024
1 parent 1447c7b commit ff72293
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 2 additions & 4 deletions ext/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -157,7 +155,7 @@ func NewDispatcher(opts *DispatcherOpts) *Dispatcher {
}

return &Dispatcher{
Logger: logger,
Logger: logger.With("component", "dispatcher"),
Processor: processor,
Error: errHandler,
Panic: panicHandler,
Expand Down
6 changes: 2 additions & 4 deletions ext/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}

Expand All @@ -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"),
},
}
}
Expand Down

0 comments on commit ff72293

Please sign in to comment.