# README
Logger
This package will provide you a generic way to handle logging.
Configuration
This plugin will configure himself automatically using the following environment variables:
LOGGER_TYPE
: define the logger output type (values:json
,text
) (default:text
)LOGGER_LEVEL
: define the minimum output level of the logger (values:panic
,fatal
,warn
,info
,debug
) (default:info
)
Usage
log := logger.Default() // Return a default logger
Context
The logger can be passed in a context so it can retain fields.
func main() {
log := logger.Default().WithFields(logrus.Fields{"caller": "main"})
add(logger.ToCtx(context.Background(), log), 1, 2)
}
def add(ctx context.Context, a, b int) int {
log := logger.Get(ctx)
log.Info("Starting add operation")
log.WithField("operation", "add")
do(logger.ToCtx(ctx, log), a,b, func(a,b int)int{return a+b})
}
def do(ctx context.Context, a,b int, op fun(int, int)int) {
log := logger.Get(ctx)
log.Info("Doing operation")
op(a,b)
}
2017-08-27 11:10:10 [INFO] Starting add operation caller=main
2017-08-27 11:10:10 [INFO] Do operation caller=main operation=add
Plugins
This logger accept plugins which can register hooks on the logger.
Known plugins
# Packages
No description provided by the author
# Functions
AddLoggerToContext add the Default() logger on top of the current context.
Default generate a logrus logger with the configuration defined in the environment and the hooks used in the plugins.
Get return the logger stored in the context or create a new one if the logger is not set.
NewContextWithLogger generate a new context (based on context.Background()) and add a Default() logger on top of it.
Plugins is the entrypoint to the global PluginManager.
ToCtx add a logger to a context.
No description provided by the author
No description provided by the author
WithLogLevel let us define the level of verbosity of the logger.
# Structs
No description provided by the author
# Interfaces
Plugin is the interface that a Plugin need to implement to be compatible with the logger library.
# Type aliases
Opt is a function-option type for the Default() method.