logger/log.go

75 lines
1.7 KiB
Go
Raw Permalink Normal View History

2024-11-15 12:17:38 +01:00
package logger
import (
"fmt"
2024-12-11 11:11:51 +01:00
"os"
2024-11-15 12:17:38 +01:00
"git.schreifuchs.ch/schreifuchs/logger/lvl"
)
// Log logs a message according to the level
func (l *Logger) Log(level lvl.Level, message string) {
l.LogChan <- &Log{
Level: level,
Message: message,
}
}
// Logf is the same as Log but with fmt.Sprintf
func (l *Logger) Logf(level lvl.Level, format string, a ...any) {
str := fmt.Sprintf(format, a...)
l.Log(level, str)
}
// Debug logs at the Debug level
func (l *Logger) Debug(a ...any) {
l.Log(lvl.Debug, fmt.Sprint(a...))
}
// Debugf logs formated at the Debug level
func (l *Logger) Debugf(format string, a ...any) {
l.Logf(lvl.Debug, format, a...)
}
// Info logs at the Info level
func (l *Logger) Info(a ...any) {
l.Log(lvl.Info, fmt.Sprint(a...))
}
// Infof logs formated at the Info level
func (l *Logger) Infof(format string, a ...any) {
l.Logf(lvl.Info, format, a...)
}
// Warn logs at the Warn level
func (l *Logger) Warn(str ...any) {
l.Log(lvl.Warn, fmt.Sprint(str...))
}
// Warnf logs formated at the Warn level
func (l *Logger) Warnf(format string, a ...any) {
l.Logf(lvl.Warn, format, a...)
}
// Error logs at the Error level
func (l *Logger) Error(a ...any) {
l.Log(lvl.Error, fmt.Sprint(a...))
}
// Errorf logs formated at the Error level
func (l *Logger) Errorf(format string, a ...any) {
l.Logf(lvl.Error, format, a...)
}
2024-12-11 11:11:51 +01:00
// Fatal logs directly do stdout and exis the application with given code.
func (l *Logger) Fatal(code int, a ...any) {
fmt.Println("Fatal:", fmt.Sprint(a...))
os.Exit(code)
}
// Fatalf logs formated directly do stdout and exis the application with given code.
func (l *Logger) Fatalf(code int, format string, a ...any) {
fmt.Println("Fatal:", fmt.Sprintf(format, a...))
os.Exit(code)
}