logger

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package logger provides utilities for working with logging using the Zap logging library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, args ...interface{})

Debug writes a debug level message using the logger from the context.

func DebugKV

func DebugKV(ctx context.Context, message string, kvs ...interface{})

DebugKV writes a message and key-value pairs at the debug level using the logger from the context.

func Debugf

func Debugf(ctx context.Context, format string, args ...interface{})

Debugf writes a formatted debug level message using the logger from the context.

func Error

func Error(ctx context.Context, args ...interface{})

Error writes an error level message using the logger from the context.

func ErrorKV

func ErrorKV(ctx context.Context, message string, kvs ...interface{})

ErrorKV writes a message and key-value pairs at the error level using the logger from the context.

func Errorf

func Errorf(ctx context.Context, format string, args ...interface{})

Errorf writes a formatted error level message using the logger from the context.

func Fatal

func Fatal(ctx context.Context, args ...interface{})

Fatal writes a fatal error level message using the logger from the context and then calls os.Exit(1).

func FatalKV

func FatalKV(ctx context.Context, message string, kvs ...interface{})

FatalKV writes a message and key-value pairs at the fatal error level using the logger from the context and then calls os.Exit(1).

func Fatalf

func Fatalf(ctx context.Context, format string, args ...interface{})

Fatalf writes a formatted fatal error level message using the logger from the context and then calls os.Exit(1).

func FromContext

func FromContext(ctx context.Context) *zap.SugaredLogger

FromContext retrieves the logger from the context. If the logger is not found in the context, it returns the global logger.

func Info

func Info(ctx context.Context, args ...interface{})

Info writes an information level message using the logger from the context.

func InfoKV

func InfoKV(ctx context.Context, message string, kvs ...interface{})

InfoKV writes a message and key-value pairs at the information level using the logger from the context.

func Infof

func Infof(ctx context.Context, format string, args ...interface{})

Infof writes a formatted information level message using the logger from the context.

func Level

func Level() zapcore.Level

Level returns the current logging level of the global logger.

func Logger

func Logger() *zap.SugaredLogger

Logger returns the global logger.

func New

func New(level zapcore.LevelEnabler, options ...zap.Option) *zap.SugaredLogger

New creates a new instance of *zap.SugaredLogger with output in simple console format. If the logging level is not provided, the default level (zap.ErrorLevel) will be used.

func Panic

func Panic(ctx context.Context, args ...interface{})

Panic writes a panic level message using the logger from the context and then calls panic().

func PanicKV

func PanicKV(ctx context.Context, message string, kvs ...interface{})

PanicKV writes a message and key-value pairs at the panic level using the logger from the context and then calls panic().

func Panicf

func Panicf(ctx context.Context, format string, args ...interface{})

Panicf writes a formatted panic level message using the logger from the context and then calls panic().

func SetLevel added in v1.1.6

func SetLevel(level zapcore.Level)

SetLevel sets the log level for the global logger.

func SetLogger

func SetLogger(l *zap.SugaredLogger)

SetLogger sets the global logger. This function is not thread-safe.

func ToContext

func ToContext(ctx context.Context, l *zap.SugaredLogger) context.Context

ToContext creates a context with the provided logger inside it.

func Warn

func Warn(ctx context.Context, args ...interface{})

Warn writes a warning level message using the logger from the context.

func WarnKV

func WarnKV(ctx context.Context, message string, kvs ...interface{})

WarnKV writes a message and key-value pairs at the warning level using the logger from the context.

func Warnf

func Warnf(ctx context.Context, format string, args ...interface{})

Warnf writes a formatted warning level message using the logger from the context.

func WithFields

func WithFields(ctx context.Context, fields ...zap.Field) context.Context

WithFields creates a logger from the one already present in the context and sets metadata using typed fields.

func WithKV

func WithKV(ctx context.Context, key string, value interface{}) context.Context

WithKV creates a logger from the one already present in the context and sets metadata. It takes a key and a value that will be inherited by child loggers.

func WithLevel

func WithLevel(lvl zapcore.Level) zap.Option

WithLevel is an option that creates a logger with the specified logging level based on an existing logger. It returns a zap.Option that wraps the existing core in a coreWithLevel with the specified level.

func WithName

func WithName(ctx context.Context, name string) context.Context

WithName creates a named logger from the one already present in the context. Child loggers will inherit names (see example).

Types

This section is empty.

Jump to

Keyboard shortcuts

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