2015-03-30 18:55:03 +02:00
|
|
|
package authboss
|
|
|
|
|
|
|
|
import (
|
2018-02-02 22:11:47 +02:00
|
|
|
"context"
|
2015-03-30 18:55:03 +02:00
|
|
|
)
|
|
|
|
|
2018-02-02 22:11:47 +02:00
|
|
|
// Logger is the basic logging structure that's required
|
|
|
|
type Logger interface {
|
|
|
|
Info(string)
|
|
|
|
Error(string)
|
|
|
|
}
|
2016-05-07 08:12:20 +02:00
|
|
|
|
2018-02-02 22:11:47 +02:00
|
|
|
// ContextLogger creates a logger from a request context
|
|
|
|
type ContextLogger interface {
|
|
|
|
FromContext(ctx context.Context) Logger
|
2015-03-30 18:55:03 +02:00
|
|
|
}
|
|
|
|
|
2018-02-02 22:11:47 +02:00
|
|
|
// Logger returns an appopriate logger for the context:
|
|
|
|
// If context is nil, then it simply returns the configured
|
|
|
|
// logger.
|
|
|
|
// If context is not nil, then it will attempt to upgrade
|
|
|
|
// the configured logger to a ContextLogger, and create
|
|
|
|
// a context-specific logger for use.
|
|
|
|
func (a *Authboss) Logger(ctx context.Context) Logger {
|
|
|
|
logger := a.Config.Core.Logger
|
|
|
|
if ctx == nil {
|
|
|
|
return logger
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxLogger, ok := logger.(ContextLogger)
|
|
|
|
if !ok {
|
|
|
|
return logger
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctxLogger.FromContext(ctx)
|
2015-03-30 18:55:03 +02:00
|
|
|
}
|