log

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package log provides logging facilities for XxSql.

Package log provides logging facilities for XxSql.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

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

Debug logs a debug message using the global logger.

func Error

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

Error logs an error message using the global logger.

func Fatal

func Fatal(format string, args ...any)

Fatal logs a fatal message using the global logger.

func Info

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

Info logs an info message using the global logger.

func SetGlobal

func SetGlobal(l *Logger)

SetGlobal sets the global logger instance.

func Warn

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

Warn logs a warning message using the global logger.

Types

type BackupInfo

type BackupInfo struct {
	Path    string
	Size    int64
	ModTime time.Time
}

BackupInfo represents information about a backup file.

type Level

type Level int

Level represents a log level.

const (
	// DEBUG level for detailed debugging information.
	DEBUG Level = iota
	// INFO level for general operational information.
	INFO
	// WARN level for warning messages.
	WARN
	// ERROR level for error messages.
	ERROR
	// FATAL level for fatal errors (exits the program).
	FATAL
)

func ParseLevel

func ParseLevel(s string) Level

ParseLevel parses a string into a log level.

func (Level) String

func (l Level) String() string

String returns the string representation of the log level.

type Logger

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

Logger is a thread-safe logger with configurable output and rotation.

func GetGlobal

func GetGlobal() *Logger

GetGlobal returns the global logger instance.

func NewLogger

func NewLogger(opts ...Option) *Logger

NewLogger creates a new Logger with the given options.

func (*Logger) Close

func (l *Logger) Close() error

Close closes the log file if opened.

func (*Logger) Debug

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

Debug logs a debug message.

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...any)

Debugf logs a formatted debug message (alias for Debug).

func (*Logger) Error

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

Error logs an error message.

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...any)

Errorf logs a formatted error message (alias for Error).

func (*Logger) Fatal

func (l *Logger) Fatal(format string, args ...any)

Fatal logs a fatal message and exits.

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...any)

Fatalf logs a formatted fatal message and exits (alias for Fatal).

func (*Logger) GetLevel

func (l *Logger) GetLevel() Level

GetLevel returns the current log level.

func (*Logger) Info

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

Info logs an info message.

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...any)

Infof logs a formatted info message (alias for Info).

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

SetLevel sets the log level at runtime.

func (*Logger) SetLevelString

func (l *Logger) SetLevelString(level string)

SetLevelString sets the log level from a string.

func (*Logger) Sync

func (l *Logger) Sync() error

Sync flushes any buffered log output.

func (*Logger) Warn

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

Warn logs a warning message.

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...any)

Warnf logs a formatted warning message (alias for Warn).

type Option

type Option func(*Logger)

Option is a functional option for Logger configuration.

func WithCaller

func WithCaller(show bool) Option

WithCaller enables/disables caller information.

func WithFile

func WithFile(path string) Option

WithFile sets the log file path.

func WithLevel

func WithLevel(level Level) Option

WithLevel sets the log level.

func WithOutput

func WithOutput(w io.Writer) Option

WithOutput sets the output writer.

func WithPrefix

func WithPrefix(prefix string) Option

WithPrefix sets a prefix for all log messages.

func WithRotation

func WithRotation(maxSizeMB, maxBackups, maxAgeDays int, compress bool) Option

WithRotation sets up log rotation.

func WithTimeFormat

func WithTimeFormat(format string) Option

WithTimeFormat sets the time format for log messages.

type Rotator

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

Rotator handles log file rotation.

func NewRotator

func NewRotator(maxSizeMB, maxBackups, maxAgeDays int, compress bool) *Rotator

NewRotator creates a new log rotator.

func (*Rotator) ForceRotate

func (r *Rotator) ForceRotate(path string) error

ForceRotate forces a rotation of the log file.

func (*Rotator) GetBackupInfo

func (r *Rotator) GetBackupInfo(logPath string) ([]BackupInfo, error)

GetBackupInfo returns information about current backup files.

func (*Rotator) Rotate

func (r *Rotator) Rotate(file *os.File) error

Rotate performs log rotation for the given file.

func (*Rotator) RotateWithPath

func (r *Rotator) RotateWithPath(path string) (*os.File, error)

RotateWithPath rotates the log file at the given path. Returns the new file handle after rotation.

func (*Rotator) ShouldRotate

func (r *Rotator) ShouldRotate(file *os.File) bool

ShouldRotate checks if the log file should be rotated.

Jump to

Keyboard shortcuts

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