mirror of
https://github.com/prometheus-community/windows_exporter
synced 2025-01-21 23:03:41 +00:00
df4f6b206b
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>
47 lines
861 B
Go
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
|
|
}
|