logger

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2025 License: AGPL-3.0 Imports: 9 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

logutil

Documentation

Index

Constants

View Source
const (
	ErrCreateLogsFileMsg = "error creating log file: %w"
	ErrCreateLogsDirMsg  = "error creating logs directory: %w"
)

Error messages

View Source
const LogsDirPath = "logs"

Variables

This section is empty.

Functions

func CloseGlobalLogger

func CloseGlobalLogger() error

CloseGlobalLogger closes the global logger

func Debug

func Debug(message string)

Convenience functions for the global logger

func Debugf

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

func Error

func Error(message string)

func ErrorWithErr

func ErrorWithErr(message string, err error)

func Errorf

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

func Fatal

func Fatal(message string)

func FatalWithErr

func FatalWithErr(message string, err error)

func Fatalf

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

func Info

func Info(message string)

func Infof

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

func InitializeGlobalLogger

func InitializeGlobalLogger(config LoggerConfig) error

InitializeGlobalLogger initializes the global logger

func SetupLogger

func SetupLogger() error

func Warn

func Warn(message string)

func Warnf

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

Types

type LogEntry

type LogEntry struct {
	Timestamp string                 `json:"timestamp"`
	Level     string                 `json:"level"`
	Message   string                 `json:"message"`
	Fields    map[string]interface{} `json:"fields,omitempty"`
	Caller    string                 `json:"caller,omitempty"`
	Error     string                 `json:"error,omitempty"`
}

LogEntry represents a structured log entry

type LogLevel

type LogLevel int

LogLevel represents the log level

const (
	DebugLevel LogLevel = iota
	InfoLevel
	WarnLevel
	ErrorLevel
	FatalLevel
)

func ParseLogLevel

func ParseLogLevel(level string) LogLevel

ParseLogLevel converts string to LogLevel

func (LogLevel) String

func (l LogLevel) String() string

String converts LogLevel to string

type Logger

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

Logger is a structured and efficient logger

var GlobalLogger *Logger

Global logger for convenience

func NewLogger

func NewLogger(config LoggerConfig) (*Logger, error)

NewLogger creates a new logger instance

func WithContext

func WithContext(ctx context.Context) *Logger

WithContext creates a logger with context

func WithField

func WithField(key string, value interface{}) *Logger

WithField creates a logger with an additional field

func WithFields

func WithFields(fields map[string]interface{}) *Logger

WithFields creates a logger with additional fields

func (*Logger) Close

func (l *Logger) Close() error

Close closes the log file

func (*Logger) Debug

func (l *Logger) Debug(message string)

Public log methods

func (*Logger) Debugf

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

func (*Logger) Error

func (l *Logger) Error(message string)

func (*Logger) ErrorWithErr

func (l *Logger) ErrorWithErr(message string, err error)

func (*Logger) Errorf

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

func (*Logger) Fatal

func (l *Logger) Fatal(message string)

func (*Logger) FatalWithErr

func (l *Logger) FatalWithErr(message string, err error)

func (*Logger) Fatalf

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

func (*Logger) Info

func (l *Logger) Info(message string)

func (*Logger) Infof

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

func (*Logger) Warn

func (l *Logger) Warn(message string)

func (*Logger) Warnf

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

func (*Logger) WithContext

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

WithContext adds context fields if available

func (*Logger) WithField

func (l *Logger) WithField(key string, value interface{}) *Logger

WithField adds a field to the logger (returns new instance)

func (*Logger) WithFields

func (l *Logger) WithFields(fields map[string]interface{}) *Logger

WithFields adds multiple fields to the logger

type LoggerConfig

type LoggerConfig struct {
	Level          LogLevel
	LogDir         string
	EnableConsole  bool
	EnableFile     bool
	EnableJSON     bool
	IncludeCaller  bool
	FileNameFormat string // "2006-01-02" para daily rotation
}

LoggerConfig logger configuration

Jump to

Keyboard shortcuts

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