logger

package
v3.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogMessage

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

LogMessage represents a single log message.

type Logger

type Logger struct {

	// True when the goroutine is running.
	Running      bool
	RunningMutex sync.Mutex
	// contains filtered or unexported fields
}

Logger is a simple, thread-safe logger. It supports various log levels, file and or console logging, basic performance tuning, automatic flushing, and size based log rotation.

func NewLogger

func NewLogger(cfg *config.Config, msgChanSize int, LocationSkip int) (*Logger, error)

NewLogger creates a new Logger instance with the provided configuration. It initializes all channels and starts the background logging goroutine.

The msgChanSize parameter controls the buffer size of the message channel, where 0 means unbuffered. LocationSkip controls the number of stack frames to skip when including the location in log messages (-1 to disable). For normal usage, LocationSkip should be set to 2. Location information is only included for ERROR, DEBUG, and FATAL log levels.

Returns an error if the log directory path cannot be set.

func (*Logger) Debug

func (l *Logger) Debug(msg string)

func (*Logger) Debugf

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

func (*Logger) Error

func (l *Logger) Error(msg string)

func (*Logger) Errorf

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

func (*Logger) Fatal

func (l *Logger) Fatal(exitCode int, timeout time.Duration, msg string)

Fatal attempts to log a message and exits the program. It exits with the given exit code either when the message is logged or the timeout duration is reached. A timeout of 0 means block indefinitely.

func (*Logger) Fatalf

func (l *Logger) Fatalf(exitCode int, timeout time.Duration, format string, args ...any)

Fatalf is a convenience function that calls Fatal with a format string.

func (*Logger) Flush

func (l *Logger) Flush()

Flush asynchronously flushes the log write buffer.

func (*Logger) GetConfigCopy

func (l *Logger) GetConfigCopy() config.Config

GetConfigCopy returns a copy of the current logger configuration.

func (*Logger) Info

func (l *Logger) Info(msg string)

func (*Logger) Infof

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

func (*Logger) Shutdown

func (l *Logger) Shutdown(timeout time.Duration) error

Shutdown synchronously flushes and waits for the logger to shutdown it's goroutine for the given timeout duration. A timeout of 0 means block indefinitely. You may want to time.Sleep(20 * time.Millisecond) before calling this function to ensure all log messages are buffered.

func (*Logger) Start

func (l *Logger) Start()

Start restarts the logger goroutine after a shutdown.

func (*Logger) SyncFlush

func (l *Logger) SyncFlush(timeout time.Duration)

SyncFlush synchronously flushes the log write buffer with the given timeout duration. A timeout of 0 means block indefinitely.

func (*Logger) UpdateConfig

func (l *Logger) UpdateConfig(cfg config.Config)

UpdateConfig updates the logger configuration with the provided settings. Nil fields are ignored.

func (*Logger) Warn

func (l *Logger) Warn(msg string)

func (*Logger) Warnf

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

Jump to

Keyboard shortcuts

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