Skip to content

Provide Logger interface to use non-std loggers #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ext/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type Dispatcher struct {
UnhandledErrFunc ErrorFunc
// ErrorLog specifies an optional logger for unexpected behavior from handlers.
// If nil, logging is done via the log package's standard logger.
ErrorLog *log.Logger
ErrorLog Logger

// handlerGroups represents the list of available handler groups, numerically sorted.
handlerGroups []int
Expand Down Expand Up @@ -95,7 +95,7 @@ type DispatcherOpts struct {
UnhandledErrFunc ErrorFunc
// ErrorLog specifies an optional logger for unexpected behavior from handlers.
// If nil, logging is done via the log package's standard logger.
ErrorLog *log.Logger
ErrorLog Logger

// MaxRoutines is used to decide how to limit the number of goroutines spawned by the dispatcher.
// This defines how many updates can be processed at the same time.
Expand All @@ -110,7 +110,7 @@ func NewDispatcher(opts *DispatcherOpts) *Dispatcher {
var errHandler DispatcherErrorHandler
var panicHandler DispatcherPanicHandler
var unhandledErrFunc ErrorFunc
var errLog *log.Logger
var errLog Logger

maxRoutines := DefaultMaxRoutines

Expand Down
10 changes: 10 additions & 0 deletions ext/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ext

import "log"

// Logger is an interface to use non standard loggers.
type Logger interface {
Printf(format string, v ...interface{})
}

var _ Logger = log.Default()
6 changes: 3 additions & 3 deletions ext/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Updater struct {
UnhandledErrFunc ErrorFunc
// ErrorLog specifies an optional logger for unexpected behavior from handlers.
// If nil, logging is done via the log package's standard logger.
ErrorLog *log.Logger
ErrorLog Logger

// stopIdling is the channel that blocks the main thread from exiting, to keep the bots running.
stopIdling chan struct{}
Expand All @@ -65,15 +65,15 @@ type UpdaterOpts struct {
UnhandledErrFunc ErrorFunc
// ErrorLog specifies an optional logger for unexpected behavior from handlers.
// If nil, logging is done via the log package's standard logger.
ErrorLog *log.Logger
ErrorLog Logger
// The dispatcher instance to be used by the updater.
Dispatcher *Dispatcher
}

// NewUpdater Creates a new Updater, as well as the necessary structures required for the associated Dispatcher.
func NewUpdater(opts *UpdaterOpts) *Updater {
var unhandledErrFunc ErrorFunc
var errLog *log.Logger
var errLog Logger

// Default dispatcher, no special settings.
dispatcher := NewDispatcher(nil)
Expand Down