Files
spend-sparrow/log/default.go
Tim Wundenberg df022c9077
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 4m8s
Build and Push Docker Image / Build-And-Push-Docker-Image (push) Successful in 4m4s
feat(account): #49 add mertrics
2025-05-10 23:27:03 +02:00

57 lines
961 B
Go

package log
import (
"fmt"
"log"
"log/slog"
"strings"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
errorMetric = promauto.NewCounter(
prometheus.CounterOpts{
Name: "spendsparrow_error_total",
Help: "The total number of errors during processing",
},
)
)
func Fatal(message string, args ...interface{}) {
errorMetric.Inc()
s := format(message, args)
log.Fatal(s)
}
func Error(message string, args ...interface{}) {
errorMetric.Inc()
s := format(message, args)
slog.Error(s)
}
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
if len(args) > 0 {
fmt.Fprintf(&w, message, args...)
} else {
w.WriteString(message)
}
return w.String()
}