You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Arikawa should (by now) all have context APIs that would allow the user to inject values into contexts. We could use this to inject our own structured logger in that would allow the user to easily debug their bot.
The logging should not deviate too far from stdlib log so we can maintain compatibility.
Proposed API:
package logger // import "github.com/diamondburned/arikawa/v4/utils/logger"// Logger is a logger that prints logs. It must be safe for concurrent use.typeLoggerinterface {
// WithValue returns a new Logger with the given key-value pair. No visual// information is required to be shown.WithValue(namestring, valueany) Logger// WithPrefix returns a new Logger with the given prefix. The prefix must be// shown before the log message.WithPrefix(prefixstring) LoggerPrint(v...any)
Printf(formatstring, v...any)
Println(v...any)
}
typestdLoggerstruct {
*log.Logger
}
// NewStandardLogger returns a new Logger that uses the standard library's log// package.funcNewStandardLogger(logger*log.Logger) Logger {
returnstdLogger{logger}
}
// DefaultLogger is the default logger used by the package. It is a standard// library logger that prints to os.Stderr.varDefaultLogger=NewStandardLogger(log.Default())
func (pstdLogger) WithValue(namestring, valueany) Logger {
returnp
}
func (pstdLogger) WithPrefix(prefixstring) Logger {
logger:=log.New(p.Writer(), p.Prefix() +": "+prefix, p.Flags())
returnstdLogger{logger}
}
// FromContext returns a Logger from the given context. If no Logger is found,// the DefaultLogger is returned.funcFromContext(ctx context.Context) Logger {
iflogger, ok:=ctx.Value(loggerKey).(Logger); ok {
returnlogger
}
returnDefaultLogger
}
Arikawa should (by now) all have context APIs that would allow the user to inject values into contexts. We could use this to inject our own structured logger in that would allow the user to easily debug their bot.
The logging should not deviate too far from stdlib log so we can maintain compatibility.
Proposed API:
Usage:
The text was updated successfully, but these errors were encountered: