2024-11-01 14:25:30 +00:00
|
|
|
package logger
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log/slog"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Info(msg string, args ...any) {
|
|
|
|
a, b := getArgs(args)
|
|
|
|
slog.Info(fmt.Sprintf(msg, a...), b...)
|
|
|
|
}
|
|
|
|
|
2024-11-04 06:05:43 +00:00
|
|
|
func Warn(msg string, args ...any) {
|
|
|
|
a, b := getArgs(args)
|
|
|
|
slog.Warn(fmt.Sprintf(msg, a...), b...)
|
|
|
|
}
|
|
|
|
|
2024-11-01 14:25:30 +00:00
|
|
|
func Error(err error, args ...any) {
|
|
|
|
a, b := getArgs(args)
|
|
|
|
slog.Error(fmt.Sprintf(err.Error(), a...), b...)
|
|
|
|
// TODO: save error log for later scrutiny
|
|
|
|
}
|
|
|
|
|
|
|
|
func getArgs(args []any) ([]any, []any) {
|
|
|
|
var a []any
|
|
|
|
var b []any
|
|
|
|
for _, arg := range args {
|
|
|
|
switch arg.(type) {
|
|
|
|
case slog.Attr:
|
|
|
|
b = append(b, arg)
|
|
|
|
default:
|
|
|
|
a = append(a, arg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return a, b
|
|
|
|
}
|