Documentation ¶
Index ¶
- Constants
- func Context(ctx context.Context) *zap.Logger
- func ContextWithFields(ctx context.Context, fields ...zap.Field) context.Context
- func ContextWithLogger(ctx context.Context, logger *zap.Logger) context.Context
- func ContextualHandler(opts ...ContextualOption) func(h http.Handler) http.Handler
- func Initialize(opts ...LoggerOption) error
- func RequestIDFrom(ctx context.Context) (string, error)
- func WithRequestID(ctx context.Context, id string) context.Context
- type ContextualOption
- type LoggerOption
- func WithDevelopment() LoggerOption
- func WithLogFile(file string) LoggerOption
- func WithLogFileCompress() LoggerOption
- func WithLogFileMaxAge(age int) LoggerOption
- func WithLogFileMaxBackups(backups int) LoggerOption
- func WithLogFileMaxSize(size int) LoggerOption
- func WithLogLevel(level string) LoggerOption
Constants ¶
const ( LEVEL_ERROR = "error" LEVEL_WARNING = "warning" LEVEL_INFO = "info" LEVEL_DEBUG = "debug" )
const (
LUMBERJACK_SCHEME = "lumberjack"
)
Variables ¶
This section is empty.
Functions ¶
func ContextWithFields ¶
ContextFields returns a new context appending fields to the contextual logger.
func ContextWithLogger ¶
ContextLogger returns a new context with given logger attached.
func ContextualHandler ¶
func ContextualHandler(opts ...ContextualOption) func(h http.Handler) http.Handler
ContextualHandler returns middleware adding a contextual logger with request IDs.
func Initialize ¶
func Initialize(opts ...LoggerOption) error
Initialize the global logger with given optional configuration parameters. This should be called only once during application bootstrapping.
func RequestIDFrom ¶
RequestIDFrom returns the request ID from context.
Types ¶
type ContextualOption ¶
ContextualOption allows optional contextual logger configuration.
func WithBaseLogger ¶
func WithBaseLogger(logger *zap.Logger) ContextualOption
BaseLogger configures the logger from which to derive the contextual logger.
func WithHeaders ¶
func WithHeaders(headers ...string) ContextualOption
WithHeaders configures which HTTP headers to log.
type LoggerOption ¶
type LoggerOption func(*config)
LoggerOption allows configuring the logger.
func WithDevelopment ¶
func WithDevelopment() LoggerOption
WithDevelopment enables more liberal stack traces.
func WithLogFile ¶
func WithLogFile(file string) LoggerOption
WithLogFile configures the the file to store log output.
func WithLogFileCompress ¶
func WithLogFileCompress() LoggerOption
WithLogFileCompress enables compression on the rotated backup files.
func WithLogFileMaxAge ¶
func WithLogFileMaxAge(age int) LoggerOption
WithLogFileMaxAge configures the age in days before a log file is removed.
func WithLogFileMaxBackups ¶
func WithLogFileMaxBackups(backups int) LoggerOption
WithLogFileMaxBackups configures the maximum amount of backup files to maintain.
func WithLogFileMaxSize ¶
func WithLogFileMaxSize(size int) LoggerOption
WithLogFileMaxSize configures the maximum log file size in MB.
func WithLogLevel ¶
func WithLogLevel(level string) LoggerOption
WithLogLevel configures the log level.