windows_exporter/log/gokit_adapter.go
Mario Trangoni df4f6b206b revive: make type exportable and remove unnecessary log word
See,
```
log/gokit_adapter.go:9:26: unexported-return: exported func NewToolkitAdapter returns unexported type *log.logAdapter, which can be annoying to use (revive)
func NewToolkitAdapter() *logAdapter {
                         ^
```

Signed-off-by: Mario Trangoni <mjtrangoni@gmail.com>
2021-12-18 19:54:31 +01:00

47 lines
861 B
Go

package log
import (
"github.com/go-kit/log/level"
)
// Returns an adapter implementing the go-kit/kit/log.Logger interface on our
// logrus logger
func NewToolkitAdapter() *Adapter {
return &Adapter{}
}
type Adapter struct{}
func (*Adapter) Log(keyvals ...interface{}) error {
var lvl level.Value
var msg string
for i := 0; i < len(keyvals); i += 2 {
switch keyvals[i] {
case "level":
tlvl, ok := keyvals[i+1].(level.Value)
if !ok {
Warnf("Could not cast level of type %T", keyvals[i+1])
} else {
lvl = tlvl
}
case "msg":
msg = keyvals[i+1].(string)
}
}
switch lvl {
case level.ErrorValue():
Errorln(msg)
case level.WarnValue():
Warnln(msg)
case level.InfoValue():
Infoln(msg)
case level.DebugValue():
Debugln(msg)
default:
Warnf("Unmatched log level: '%v' for message %q", lvl, msg)
}
return nil
}