1
0
mirror of https://github.com/volatiletech/authboss.git synced 2024-11-24 08:42:17 +02:00
authboss/logger.go

37 lines
798 B
Go
Raw Normal View History

package authboss
import (
"context"
)
// Logger is the basic logging structure that's required
type Logger interface {
Info(string)
Error(string)
}
2016-05-07 08:12:20 +02:00
// ContextLogger creates a logger from a request context
type ContextLogger interface {
FromContext(ctx context.Context) Logger
}
// 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)
}