62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
|
package logger
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"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...)
|
||
|
}
|