Documentation
¶
Index ¶
- Constants
- Variables
- func AddToLogContext(ctx context.Context, args ...any) context.Context
- func Die(msg string, args ...any)
- func GetRequestUuid(ctx context.Context) string
- func LogDebug(ctx context.Context, msg string)
- func LogDebugf(ctx context.Context, msg string, args ...interface{})
- func LogError(ctx context.Context, msg string)
- func LogErrorf(ctx context.Context, msg string, args ...interface{})
- func LogInfo(ctx context.Context, msg string)
- func LogInfof(ctx context.Context, msg string, args ...interface{})
- func LogWarn(ctx context.Context, msg string)
- func LogWarnf(ctx context.Context, msg string, args ...interface{})
- func LoggerAddHandler(ctx context.Context, ...) context.Context
- func LoggerDebugFunc(ctx context.Context, f func() string)
- func LoggerDummyContext() context.Context
- func LoggerGetLevel(ctx context.Context) string
- func LoggerNewContext(ctx context.Context) context.Context
- func LoggerNewRequest(ctx context.Context) context.Context
- func LoggerSetLevel(ctx context.Context, levelStr string) context.Context
- func SetProcessName(name string)
- func TranferLogContext(sourceCtx context.Context, destCtx context.Context) context.Context
- type EgLogger
- func (l EgLogger) Crit(msg string, args ...any)
- func (l EgLogger) Debug(msg string, args ...any)
- func (l EgLogger) Error(msg string, args ...any)
- func (l EgLogger) Info(msg string, args ...any)
- func (l EgLogger) New(args ...any) EgLogger
- func (l EgLogger) Sync() error
- func (l EgLogger) Warn(msg string, args ...any)
Constants ¶
const LogLevel = "loglevel"
const LoggerKey = "logger"
const ProcessPidKey = "pid"
const RequestUuidKey = "request-uuid"
Public context key strings (kept for backward compatibility)
Variables ¶
var ProcessName = os.Args[0]
ProcessName is set via SetProcessName and included in syslog output
Functions ¶
func AddToLogContext ¶
AddToLogContext adds key-value pairs to the context's additional log fields. Args should be tuples: "key1", "val1", "key2", "val2".
func GetRequestUuid ¶
GetRequestUuid returns the request UUID from the context, or empty string if not set.
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 ¶
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 ¶
LoggerDummyContext returns a context with an initialized logger (empty context).
func LoggerGetLevel ¶
LoggerGetLevel returns the current log level name from the context.
func LoggerNewContext ¶
LoggerNewContext initializes a new logger in the context with the current PID.
func LoggerNewRequest ¶
LoggerNewRequest generates a new UUID for request tracking and adds it to the context.
func LoggerSetLevel ¶
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.
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 LoggerWContext ¶
LoggerWContext returns a logger initialized with values from the context (pid, request UUID, and additional fields). Extra args are added as key-value pairs.