Documentation ¶
Overview ¶
Package log implements some utilities for our logging. E.g. it provides an utility for parsing the specified log level and a context aware logging function, which can be used to extend the list of fields for a log line, with the fields from the passed in context.
Index ¶
- Constants
- func ContextWithValue(ctx context.Context, fields ...zapcore.Field) context.Context
- func Debug(ctx context.Context, msg string, fields ...zapcore.Field)
- func Error(ctx context.Context, msg string, fields ...zapcore.Field)
- func Fatal(ctx context.Context, msg string, fields ...zapcore.Field)
- func Info(ctx context.Context, msg string, fields ...zapcore.Field)
- func Panic(ctx context.Context, msg string, fields ...zapcore.Field)
- func Setup(level, format string)
- func Warn(ctx context.Context, msg string, fields ...zapcore.Field)
Constants ¶
const LogKey ctxKeyLog = 0
LogKey is the key that holds the log fields in a context.
Variables ¶
This section is empty.
Functions ¶
func ContextWithValue ¶
ContextWithValue takes an existing context and adds all the provided fields to the context so that they will then be logged for each line where the returned context is used. In the first step we have to check if the context already contains some log fields. If this is the case, we append the provided fields, so that the new context contains all fields.
func Debug ¶
Debug is a wrapper around the zap.L().Debug() function, which adds all fields from the passed context to the log message.
func Error ¶
Error is a wrapper around the zap.L().Error() function, which adds all fields from the passed context to the log message.
func Fatal ¶
Fatal is a wrapper around the zap.L().Fatal() function, which adds all fields from the passed context to the log message.
func Info ¶
Info is a wrapper around the zap.L().Info() function, which adds all fields from the passed context to the log message.
func Panic ¶
Panic is a wrapper around the zap.L().Panic() function, which adds all fields from the passed context to the log message.
func Setup ¶ added in v0.9.0
func Setup(level, format string)
Setup our logging library. The logs can be written in console format (the console format is compatible with logfmt) or in json format. The default is console, because it is better to read during development. In a production environment you should consider to use json, so that the logs can be parsed by a logging system like Elasticsearch. Next to the log format it is also possible to configure the log leven. The accepted values are "debug", "info", "warn", "error", "fatal" and "panic". The default log level is "info".
Types ¶
This section is empty.