2024-05-11 05:43:43 +08:00
|
|
|
package logger
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/influxdata/telegraf/selfstat"
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestErrorCounting(t *testing.T) {
|
|
|
|
|
reg := selfstat.Register(
|
|
|
|
|
"gather",
|
|
|
|
|
"errors",
|
|
|
|
|
map[string]string{"input": "test"},
|
|
|
|
|
)
|
2024-07-26 23:09:21 +08:00
|
|
|
iLog := New("inputs", "test", "")
|
2024-05-11 05:43:43 +08:00
|
|
|
iLog.RegisterErrorCallback(func() {
|
|
|
|
|
reg.Incr(1)
|
|
|
|
|
})
|
|
|
|
|
iLog.Error("something went wrong")
|
|
|
|
|
iLog.Errorf("something went wrong")
|
|
|
|
|
|
|
|
|
|
require.Equal(t, int64(2), reg.Get())
|
|
|
|
|
}
|