log

package
v0.0.0-...-8d15855 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const LogLevel = "loglevel"
View Source
const LoggerKey = "logger"
View Source
const ProcessPidKey = "pid"
View Source
const RequestUuidKey = "request-uuid"

Public context key strings (kept for backward compatibility)

Variables

View Source
var ProcessName = os.Args[0]

ProcessName is set via SetProcessName and included in syslog output

Functions

func AddToLogContext

func AddToLogContext(ctx context.Context, args ...any) context.Context

AddToLogContext adds key-value pairs to the context's additional log fields. Args should be tuples: "key1", "val1", "key2", "val2".

func Die

func Die(msg string, args ...any)

Die logs a critical message and panics.

func GetRequestUuid

func GetRequestUuid(ctx context.Context) string

GetRequestUuid returns the request UUID from the context, or empty string if not set.

func LogDebug

func LogDebug(ctx context.Context, msg string)

func LogDebugf

func LogDebugf(ctx context.Context, msg string, args ...interface{})

func LogError

func LogError(ctx context.Context, msg string)

func LogErrorf

func LogErrorf(ctx context.Context, msg string, args ...interface{})

func LogInfo

func LogInfo(ctx context.Context, msg string)

func LogInfof

func LogInfof(ctx context.Context, msg string, args ...interface{})

func LogWarn

func LogWarn(ctx context.Context, msg string)

func LogWarnf

func LogWarnf(ctx context.Context, msg string, args ...interface{})

func LoggerAddHandler

func LoggerAddHandler(ctx context.Context, f func(msg string, level string, attrs map[string]any) error) context.Context

LoggerAddHandler adds an additional handler to the logger. The function receives message, level name, and attributes map for each log entry.

func LoggerDebugFunc

func LoggerDebugFunc(ctx context.Context, f func() string)

LoggerDebugFunc executes f only if the logger is in debug mode. If f returns a non-empty string, it is logged at debug level.

func LoggerDummyContext

func LoggerDummyContext() context.Context

LoggerDummyContext returns a context with an initialized logger (empty context).

func LoggerGetLevel

func LoggerGetLevel(ctx context.Context) string

LoggerGetLevel returns the current log level name from the context.

func LoggerNewContext

func LoggerNewContext(ctx context.Context) context.Context

LoggerNewContext initializes a new logger in the context with the current PID.

func LoggerNewRequest

func LoggerNewRequest(ctx context.Context) context.Context

LoggerNewRequest generates a new UUID for request tracking and adds it to the context.

func LoggerSetLevel

func LoggerSetLevel(ctx context.Context, levelStr string) context.Context

LoggerSetLevel sets the log level for the logger in the context. Valid levels: debug, info, warn, error, crit.

func SetProcessName

func SetProcessName(name string)

SetProcessName sets the process name used in log output.

func TranferLogContext

func TranferLogContext(sourceCtx context.Context, destCtx context.Context) context.Context

TranferLogContext copies logger state from one context to another.

Types

type EgLogger

type EgLogger struct {
	// contains filtered or unexported fields
}

EgLogger is the primary logging interface returned by LoggerWContext. It wraps zap.SugaredLogger for high-performance structured logging.

func Logger

func Logger() EgLogger

Logger returns a logger without a specific context.

func LoggerWContext

func LoggerWContext(ctx context.Context, args ...any) EgLogger

LoggerWContext returns a logger initialized with values from the context (pid, request UUID, and additional fields). Extra args are added as key-value pairs.

func (EgLogger) Crit

func (l EgLogger) Crit(msg string, args ...any)

func (EgLogger) Debug

func (l EgLogger) Debug(msg string, args ...any)

func (EgLogger) Error

func (l EgLogger) Error(msg string, args ...any)

func (EgLogger) Info

func (l EgLogger) Info(msg string, args ...any)

func (EgLogger) New

func (l EgLogger) New(args ...any) EgLogger

New returns a child logger with additional key-value pairs.

func (EgLogger) Sync

func (l EgLogger) Sync() error

Sync flushes any buffered log entries.

func (EgLogger) Warn

func (l EgLogger) Warn(msg string, args ...any)

Jump to

Keyboard shortcuts

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