Documentation
¶
Overview ¶
Package logger provides a simple logging framework that supports log levels.
Index ¶
- Variables
- func LevelStrings() []string
- type Level
- type Logger
- func (l *Logger) Always(msg string)
- func (l *Logger) Alwaysf(f string, a ...any)
- func (l *Logger) Debug(msg string)
- func (l *Logger) Debugf(f string, a ...any)
- func (l *Logger) Error(msg string)
- func (l *Logger) Errorf(f string, a ...any)
- func (l *Logger) Info(msg string)
- func (l *Logger) Infof(f string, a ...any)
- func (l *Logger) Level() Level
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) Warn(msg string)
- func (l *Logger) Warnf(f string, a ...any)
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidLogLevel = errors.New("invalid log level")
ErrInvalidLogLevel is returned when an invalid log level is provided.
Functions ¶
func LevelStrings ¶ added in v0.0.1
func LevelStrings() []string
LevelStrings returns a slice of all String values of the enum
Types ¶
type Level ¶
type Level int
Level represents the severity of a log message. It can be one of DEBUG, INFO, WARN, ERROR, ALWAYS, or SILENT.
const ( // SILENT indicates no logging output. SILENT Level = iota - 1 // DEBUG indicates detailed debug information. DEBUG // INFO indicates normal operational messages. INFO // WARN indicates potentially harmful situations. WARN // ERROR indicates error events. ERROR // ALWAYS indicates messages always shown regardless of current log level. ALWAYS )
func LevelString ¶ added in v0.0.1
LevelString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func LevelValues ¶ added in v0.0.1
func LevelValues() []Level
LevelValues returns all values of the enum
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger holds the configuration for logging. It includes the current logging level, the output writer, and color mappings for each log level.
func NewCustom ¶
NewCustom creates a new Logger instance with the specified log level and output writer. If an invalid log level is provided, it defaults to INFO.
func (*Logger) Always ¶
Always logs a message at the ALWAYS level, regardless of the current log level.