zap

package module
v0.0.0-...-ac4dbc3 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(err error) zap.Field

func NamedError

func NamedError(key string, e error) zap.Field

func NewErrorMetricsCore

func NewErrorMetricsCore(registry prometheus.Registerer, metricName, errorKey string) zapcore.Core

NewErrorMetricsCore return core that will send metrics when log error

Example
log := zap.NewExample()
registry := prometheus.NewRegistry()
log = log.WithOptions(zap.WrapCore(func(origin zapcore.Core) zapcore.Core {
	return zapcore.NewTee(origin, NewErrorMetricsCore(registry, "errors", "error"))
}),
)

log.Error("test")
log.Error("test", Error(&app.Error{Code: app.ETEST, Message: "test"}))
log.With(zap.String("logger", "sublogger")).Error("test", Error(&app.Error{Op: "test", Code: app.ETEST, Message: "test"}))
Output:
{"level":"error","msg":"test"}
{"level":"error","msg":"test","error":{"msg":"test","code":"test_error_code","trace":[]}}
{"level":"error","msg":"test","logger":"sublogger","error":{"msg":"test","code":"test_error_code","trace":["test"]}}

Types

This section is empty.

Jump to

Keyboard shortcuts

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