mirror of
https://github.com/mjl-/mox.git
synced 2024-12-25 16:03:48 +03:00
add metrics that track how many error/warn/info logging is happening
This commit is contained in:
parent
056b571fb6
commit
b750668152
1 changed files with 33 additions and 0 deletions
33
mlog/log.go
33
mlog/log.go
|
@ -25,10 +25,34 @@ import (
|
|||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
var noctx = context.Background()
|
||||
|
||||
var (
|
||||
metricLogInfo = promauto.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Name: "mox_logging_level_info_total",
|
||||
Help: "Total number of logging events at level info.",
|
||||
},
|
||||
)
|
||||
metricLogWarn = promauto.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Name: "mox_logging_level_warn_total",
|
||||
Help: "Total number of logging events at level warn.",
|
||||
},
|
||||
)
|
||||
metricLogError = promauto.NewCounter(
|
||||
prometheus.CounterOpts{
|
||||
Name: "mox_logging_level_error_total",
|
||||
Help: "Total number of logging events at level error.",
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
// Logfmt enabled output in logfmt, instead of output more suitable for
|
||||
// command-line tools. Must be set early in a program lifecycle.
|
||||
var Logfmt bool
|
||||
|
@ -325,6 +349,15 @@ func (h *handler) Handle(ctx context.Context, r slog.Record) error {
|
|||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if r.Level >= LevelInfo {
|
||||
if r.Level == LevelInfo {
|
||||
metricLogInfo.Inc()
|
||||
} else if r.Level <= LevelWarn {
|
||||
metricLogWarn.Inc()
|
||||
} else if r.Level <= LevelError {
|
||||
metricLogError.Inc()
|
||||
}
|
||||
}
|
||||
if hideData, hideAuth := traceLevel(l, r.Level); hideData {
|
||||
r.Message = "..."
|
||||
} else if hideAuth {
|
||||
|
|
Loading…
Reference in a new issue