Documentation ¶
Overview ¶
Package logging implements a structured-log model with common functionalities and utility functions. The log messages are augmented with additional fields to enrich the response with application metadata. The standard syslog levels are automatically mapped to the corresponding zap log levels.
This is a Zap-based custom implementation of the configuration model described in the following article:
- Nicola Asuni, 2014-08-11, "Software Logging Format", https://technick.net/guides/software/software_logging_format/
Index ¶
- Variables
- func Close(ctx context.Context, obj io.Closer, errorMessage string)
- func FromContext(ctx context.Context) *zap.Logger
- func NewDefaultLogger(name, version, release, format, level string) (*zap.Logger, error)
- func NewLogger(opts ...Option) (*zap.Logger, error)
- func NopLogger() *zap.Logger
- func ParseLevel(l string) (zapcore.Level, error)
- func Sync(s Syncer)
- func WithComponent(ctx context.Context, comp string) *zap.Logger
- func WithComponentAndMethod(ctx context.Context, comp, method string) *zap.Logger
- func WithLevelFunctionHook(l *zap.Logger, fn IncrementLogMetricsFunc) *zap.Logger
- func WithLogger(ctx context.Context, l *zap.Logger) context.Context
- type Format
- type IncrementLogMetricsFunc
- type Option
- func WithErrorOutputPaths(paths []string) Option
- func WithFields(f ...zap.Field) Option
- func WithFormat(f Format) Option
- func WithFormatStr(f string) Option
- func WithIncrementLogMetricsFunc(fn IncrementLogMetricsFunc) Option
- func WithLevel(l zapcore.Level) Option
- func WithLevelStr(l string) Option
- func WithOutputPaths(paths []string) Option
- type Syncer
Constants ¶
This section is empty.
Variables ¶
var LogFatal = zap.L().Fatal
LogFatal calls the default fatal logger.
Functions ¶
func FromContext ¶
FromContext retrieves a logger instance form the given context.
func NewDefaultLogger ¶
NewDefaultLogger configures a logger with the default fields.
func ParseLevel ¶
ParseLevel converts syslog standard levels to zap a log level.
func WithComponent ¶
WithComponent creates a child logger with an extra "component" tag.
func WithComponentAndMethod ¶
WithComponentAndMethod creates a child logger with extra "component" and "method" tags.
func WithLevelFunctionHook ¶
func WithLevelFunctionHook(l *zap.Logger, fn IncrementLogMetricsFunc) *zap.Logger
WithLevelFunctionHook registers a function with a level string argument which will be called each time the Logger writes out an Entry.
Types ¶
type Format ¶
type Format int8
Format represents the logging output format to adopt.
const ( // ConsoleFormat will print the log in a human friendly format. ConsoleFormat Format // JSONFormat will print the log in a machine readable format. JSONFormat )
func ParseFormat ¶
ParseFormat converts a string to a log format.
type IncrementLogMetricsFunc ¶
type IncrementLogMetricsFunc func(string)
IncrementLogMetricsFunc is a type alias for the logging metric function.
type Option ¶
type Option func(*config) error
Option is a type alias for a function that configures the application logger.
func WithErrorOutputPaths ¶
WithErrorOutputPaths manually overrides the ErrorOutputPaths option.
func WithFields ¶
WithFields add static fields to the logger.
func WithFormat ¶
WithFormat manually overrides the environment log format.
func WithFormatStr ¶
WithFormatStr manually overrides the environment log format.
func WithIncrementLogMetricsFunc ¶
func WithIncrementLogMetricsFunc(fn IncrementLogMetricsFunc) Option
WithIncrementLogMetricsFunc replaces the default log level metrics function.
func WithLevelStr ¶
WithLevelStr manually overrides the environment log level.
func WithOutputPaths ¶
WithOutputPaths manually overrides the OutputPaths option.