fix: refine logging
This commit was merged in pull request #293.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
@@ -16,11 +19,32 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
func Error(message string, err error) {
|
||||
slog.Error(message + ": " + err.Error())
|
||||
func Fatal(message string, args ...interface{}) {
|
||||
s := format(message, args)
|
||||
log.Fatal(s)
|
||||
|
||||
errorMetric.Inc()
|
||||
}
|
||||
func ErrorMsg(message string) {
|
||||
slog.Error(message)
|
||||
|
||||
func Error(message string, args ...interface{}) {
|
||||
s := format(message, args)
|
||||
slog.Error(s)
|
||||
|
||||
errorMetric.Inc()
|
||||
}
|
||||
|
||||
func Warn(message string, args ...interface{}) {
|
||||
s := format(message, args)
|
||||
slog.Warn(s)
|
||||
}
|
||||
|
||||
func Info(message string, args ...interface{}) {
|
||||
s := format(message, args)
|
||||
slog.Info(s)
|
||||
}
|
||||
|
||||
func format(message string, args []interface{}) string {
|
||||
var w strings.Builder
|
||||
fmt.Fprintf(&w, message, args)
|
||||
return w.String()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user