diff --git a/mlog/log.go b/mlog/log.go index d041c98..122599a 100644 --- a/mlog/log.go +++ b/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 {