logger

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

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

Go to latest
Published: Sep 5, 2026 License: MIT Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalLogger = Default()

GlobalLogger is the default logger instance

Functions

func Debug

func Debug(msg string, keysAndValues ...interface{})

Debug logs to the global logger

func Error

func Error(msg string, keysAndValues ...interface{})

Error logs to the global logger

func Fatal

func Fatal(msg string, keysAndValues ...interface{})

Fatal logs to the global logger and exits

func Info

func Info(msg string, keysAndValues ...interface{})

Info logs to the global logger

func SetGlobalLogger

func SetGlobalLogger(logger *Logger)

SetGlobalLogger sets the global logger instance

func SetLevel

func SetLevel(level string)

SetLevel sets the logging level for the global logger

func Sync

func Sync()

Sync flushes any buffered log entries

func Warn

func Warn(msg string, keysAndValues ...interface{})

Warn logs to the global logger

Types

type Config

type Config struct {
	Level      string `json:"level"`
	Format     string `json:"format"`
	Output     string `json:"output"`
	Structured bool   `json:"structured"`
	Service    string `json:"service"`
	Version    string `json:"version"`
}

Config holds logger configuration

type Entry

type Entry struct {
	Timestamp  time.Time              `json:"timestamp"`
	Level      string                 `json:"level"`
	Message    string                 `json:"message"`
	Service    string                 `json:"service,omitempty"`
	Version    string                 `json:"version,omitempty"`
	RequestID  string                 `json:"request_id,omitempty"`
	TraceID    string                 `json:"trace_id,omitempty"`
	UserID     string                 `json:"user_id,omitempty"`
	TenantID   string                 `json:"tenant_id,omitempty"`
	File       string                 `json:"file,omitempty"`
	Function   string                 `json:"function,omitempty"`
	Line       int                    `json:"line,omitempty"`
	Fields     map[string]interface{} `json:"fields,omitempty"`
	Error      string                 `json:"error,omitempty"`
	StackTrace []string               `json:"stack_trace,omitempty"`
}

Entry represents a log entry

type Level

type Level int

Level represents a logging level

const (
	DebugLevel Level = iota
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
)

func LevelFromString

func LevelFromString(s string) Level

LevelFromString converts a string to a Level

func (Level) String

func (l Level) String() string

String returns the string representation of a level

type Logger

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

Logger represents a structured logger

func ContextLogger

func ContextLogger(ctx context.Context, logger *Logger) *Logger

ContextLogger extracts logger with context information

func Default

func Default() *Logger

Default creates a logger with default configuration

func New

func New(config Config) *Logger

New creates a new logger with the given configuration

func NewFromConfig

func NewFromConfig(level, format, output string, structured bool) *Logger

NewFromConfig creates a logger from a configuration struct

func (*Logger) Debug

func (l *Logger) Debug(msg string, keysAndValues ...interface{})

Debug logs a debug message

func (*Logger) Error

func (l *Logger) Error(msg string, keysAndValues ...interface{})

Error logs an error message

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, keysAndValues ...interface{})

Fatal logs a fatal message and exits

func (*Logger) Info

func (l *Logger) Info(msg string, keysAndValues ...interface{})

Info logs an info message

func (*Logger) Warn

func (l *Logger) Warn(msg string, keysAndValues ...interface{})

Warn logs a warning message

func (*Logger) WithContext

func (l *Logger) WithContext(ctx context.Context) *Logger

WithContext creates a new logger with context information

Jump to

Keyboard shortcuts

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