fix: move implementation to "internal" package
This commit was merged in pull request #138.
This commit is contained in:
56
internal/log/default.go
Normal file
56
internal/log/default.go
Normal file
@@ -0,0 +1,56 @@
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user