logging

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package logging provides structured logging with multiple output formats and levels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

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

Debug logs a debug message using the global logger

func DebugIf added in v1.6.0

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

DebugIf logs a debug message only if debug mode is enabled. This is more efficient than checking os.Getenv on every call.

func DebugJSON added in v1.6.0

func DebugJSON(msg string, jsonKey string, data interface{}, extraArgs ...any)

DebugJSON logs a debug message with JSON-marshaled data. If JSON marshaling fails, logs the error and falls back to fmt.Sprintf.

func DebugWith

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

DebugWith logs a debug message with attributes using the global logger

func Error

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

Error logs an error message using the global logger

func ErrorWith

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

ErrorWith logs an error message with attributes using the global logger

func ErrorWithErr

func ErrorWithErr(msg string, err error, args ...any)

ErrorWithErr logs an error with an error object using the global logger

func Info

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

Info logs an info message using the global logger

func InfoWith

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

InfoWith logs an info message with attributes using the global logger

func IsDebugEnabled added in v1.6.0

func IsDebugEnabled() bool

IsDebugEnabled returns true if HEX_DEBUG environment variable is set. Result is cached after first check for performance.

func SetGlobalLogger

func SetGlobalLogger(logger *Logger)

SetGlobalLogger sets the global logger instance

func Warn

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

Warn logs a warning message using the global logger

func WarnWith

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

WarnWith logs a warning message with attributes using the global logger

func WithConversationID

func WithConversationID(ctx context.Context, id string) context.Context

WithConversationID adds a conversation ID to the context

func WithRequestID

func WithRequestID(ctx context.Context, id string) context.Context

WithRequestID adds a request ID to the context

Types

type Config

type Config struct {
	Level     Level
	Format    Format
	Writer    io.Writer
	LogFile   string
	AddSource bool
}

Config holds logger configuration

type Format

type Format int

Format represents log output format

const (
	// FormatText outputs logs in plain text format
	FormatText Format = iota
	// FormatJSON outputs logs in JSON format
	FormatJSON
)

type Level

type Level int

Level represents log severity levels

const (
	// LevelDebug enables debug-level logging
	LevelDebug Level = iota
	// LevelInfo enables info-level logging
	LevelInfo
	// LevelWarn enables warning-level logging
	LevelWarn
	// LevelError enables error-level logging
	LevelError
)

func LevelFromString

func LevelFromString(s string) Level

LevelFromString converts a string to a log level

type Logger

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

Logger wraps slog.Logger with additional functionality

func Default

func Default() *Logger

Default returns the global logger instance

func NewLogger

func NewLogger(cfg Config) *Logger

NewLogger creates a new logger with the given configuration

func NewLoggerWithFile

func NewLoggerWithFile(cfg Config) (*Logger, error)

NewLoggerWithFile creates a logger that writes to a file and optionally to writer

func (*Logger) Close

func (l *Logger) Close() error

Close closes any open file handles

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...any)

Debug logs a debug message

func (*Logger) DebugWith

func (l *Logger) DebugWith(msg string, args ...any)

DebugWith logs a debug message with structured attributes

func (*Logger) DebugWithContext

func (l *Logger) DebugWithContext(ctx context.Context, msg string, args ...any)

DebugWithContext logs a debug message with context metadata

func (*Logger) Error

func (l *Logger) Error(msg string, args ...any)

Error logs an error message

func (*Logger) ErrorWith

func (l *Logger) ErrorWith(msg string, args ...any)

ErrorWith logs an error message with structured attributes

func (*Logger) ErrorWithContext

func (l *Logger) ErrorWithContext(ctx context.Context, msg string, args ...any)

ErrorWithContext logs an error message with context metadata

func (*Logger) ErrorWithErr

func (l *Logger) ErrorWithErr(msg string, err error, args ...any)

ErrorWithErr logs an error message with an error object

func (*Logger) Info

func (l *Logger) Info(msg string, args ...any)

Info logs an info message

func (*Logger) InfoWith

func (l *Logger) InfoWith(msg string, args ...any)

InfoWith logs an info message with structured attributes

func (*Logger) InfoWithContext

func (l *Logger) InfoWithContext(ctx context.Context, msg string, args ...any)

InfoWithContext logs an info message with context metadata

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...any)

Warn logs a warning message

func (*Logger) WarnWith

func (l *Logger) WarnWith(msg string, args ...any)

WarnWith logs a warning message with structured attributes

func (*Logger) WarnWithContext

func (l *Logger) WarnWithContext(ctx context.Context, msg string, args ...any)

WarnWithContext logs a warning message with context metadata

Jump to

Keyboard shortcuts

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