log

package
v0.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 6 Imported by: 2

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

View Source
const LogKey ctxKeyLog = 0

LogKey is the key that holds the log fields in a context.

Variables

This section is empty.

Functions

func ContextWithValue

func ContextWithValue(ctx context.Context, fields ...zapcore.Field) context.Context

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

func Debug(ctx context.Context, msg string, fields ...zapcore.Field)

Debug is a wrapper around the zap.L().Debug() function, which adds all fields from the passed context to the log message.

func Error

func Error(ctx context.Context, msg string, fields ...zapcore.Field)

Error is a wrapper around the zap.L().Error() function, which adds all fields from the passed context to the log message.

func Fatal

func Fatal(ctx context.Context, msg string, fields ...zapcore.Field)

Fatal is a wrapper around the zap.L().Fatal() function, which adds all fields from the passed context to the log message.

func Info

func Info(ctx context.Context, msg string, fields ...zapcore.Field)

Info is a wrapper around the zap.L().Info() function, which adds all fields from the passed context to the log message.

func Panic

func Panic(ctx context.Context, msg string, fields ...zapcore.Field)

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".

func Warn

func Warn(ctx context.Context, msg string, fields ...zapcore.Field)

Warn is a wrapper around the zap.L().Warn() function, which adds all fields from the passed context to the log message.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL