Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Attr ¶
Attr is an alias for slog.Attr, used to define structured attributes for log messages.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is an asynchronous logger that processes log messages in a separate goroutine. It provides methods to log messages at different severity levels (Debug, Info, Warn, Error).
func GetLogger ¶
func GetLogger(config LoggerConfig) *Logger
GetLogger returns the singleton instance of the Logger. If the logger has not been initialized, it initializes it with the provided configuration.
func (*Logger) Shutdown ¶
func (l *Logger) Shutdown()
Shutdown gracefully shuts down the logger by ensuring that all pending log messages in the logChan channel are processed before the logger stops.
Steps:
- It closes the logChan channel to signal the processLogs goroutine that no more log messages will be sent.
- It waits for the done channel to be closed, which indicates that the processLogs goroutine has finished processing all remaining log messages and has exited.
This ensures that no log messages are lost during shutdown and that the logger shuts down cleanly.
type LoggerConfig ¶
LoggerConfig defines the configuration for the Logger.
Fields: - BufferSize: The size of the buffered channel used to enqueue log messages for asynchronous processing. - Handler: The slog.Handler used to format and output log messages.