logging

package
v0.3.0-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseLogger

func CloseLogger()

CloseLogger closes current logger's file handles and clears the logger. Call during shutdown to release file descriptors. Safe to call multiple times.

func Debug

func Debug(args ...interface{})

Debug logs a debug message

func Debugf

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

Debugf logs a formatted debug message

func Error

func Error(args ...interface{})

Error logs an error message

func Errorf

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

Errorf logs a formatted error message

func Fatal

func Fatal(args ...interface{})

Fatal logs a fatal message and exits with status code 1. Note: This function calls os.Exit() and cannot be tested in unit tests. Any test attempting to cover this function would terminate the test process.

func Fatalf

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

Fatalf logs a formatted fatal message and exits with status code 1. Note: This function calls os.Exit() and cannot be tested in unit tests. Any test attempting to cover this function would terminate the test process.

func GetFileOutputs

func GetFileOutputs(output string) []string

GetFileOutputs extracts file paths from a comma-separated output string. Returns only file paths (excludes "stdout" and "stderr"). Returns nil if no file outputs are found.

func Info

func Info(args ...interface{})

Info logs an info message

func Infof

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

Infof logs a formatted info message

func InitLogger

func InitLogger(cfg *Config) error

InitLogger initializes or reloads the global logger based on configuration. It atomically swaps in the new logger and closes previous file handles to prevent leaks. This function is safe to call multiple times for config reloading.

func L

func L() *logrus.Logger

L returns the current logger instance. Callers should NOT cache the returned pointer across config reloads; instead, call logging.L() when you need to log. This ensures you always get the current logger after config reloads.

func Warn

func Warn(args ...interface{})

Warn logs a warning message

func Warnf

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

Warnf logs a formatted warning message

func WithField

func WithField(key string, value interface{}) *logrus.Entry

WithField returns a logger with a single field

func WithFields

func WithFields(fields logrus.Fields) *logrus.Entry

WithFields returns a logger with multiple fields

Types

type Config

type Config struct {
	Level      string `yaml:"level"`        // debug, info, warn, error
	Format     string `yaml:"format"`       // text, json
	Output     string `yaml:"output"`       // stdout, file path, or "stdout,/path/to/file.log"
	MaxSizeMB  int    `yaml:"max_size_mb"`  // Max size in MB before rotation (0 = no rotation)
	MaxBackups int    `yaml:"max_backups"`  // Max number of old log files to keep
	MaxAgeDays int    `yaml:"max_age_days"` // Max age in days to keep log files (0 = no limit)
	Compress   bool   `yaml:"compress"`     // Compress rotated files
}

Config represents logging configuration

Jump to

Keyboard shortcuts

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