Documentation
¶
Index ¶
- type LogMessage
- type Logger
- func (l *Logger) Debug(msg string)
- func (l *Logger) Debugf(format string, args ...any)
- func (l *Logger) Error(msg string)
- func (l *Logger) Errorf(format string, args ...any)
- func (l *Logger) Fatal(exitCode int, timeout time.Duration, msg string)
- func (l *Logger) Fatalf(exitCode int, timeout time.Duration, format string, args ...any)
- func (l *Logger) Flush()
- func (l *Logger) GetConfigCopy() config.Config
- func (l *Logger) Info(msg string)
- func (l *Logger) Infof(format string, args ...any)
- func (l *Logger) Shutdown(timeout time.Duration) error
- func (l *Logger) Start()
- func (l *Logger) SyncFlush(timeout time.Duration)
- func (l *Logger) UpdateConfig(cfg config.Config)
- func (l *Logger) Warn(msg string)
- func (l *Logger) Warnf(format string, args ...any)
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 ¶
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) Fatal ¶
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) GetConfigCopy ¶
GetConfigCopy returns a copy of the current logger configuration.
func (*Logger) Shutdown ¶
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 ¶
SyncFlush synchronously flushes the log write buffer with the given timeout duration. A timeout of 0 means block indefinitely.
func (*Logger) UpdateConfig ¶
UpdateConfig updates the logger configuration with the provided settings. Nil fields are ignored.