Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
35
plugins/common/logrus/hook.go
Normal file
35
plugins/common/logrus/hook.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package logrus
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log" //nolint:depguard // Allow exceptional but valid use of log here.
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var once sync.Once
|
||||
|
||||
type LogHook struct {
|
||||
}
|
||||
|
||||
// InstallHook installs a logging hook into the logrus standard logger, diverting all logs
|
||||
// through the Telegraf logger at debug level. This is useful for libraries
|
||||
// that directly log to the logrus system without providing an override method.
|
||||
func InstallHook() {
|
||||
once.Do(func() {
|
||||
logrus.SetOutput(io.Discard)
|
||||
logrus.AddHook(&LogHook{})
|
||||
})
|
||||
}
|
||||
|
||||
func (*LogHook) Fire(entry *logrus.Entry) error {
|
||||
msg := strings.ReplaceAll(entry.Message, "\n", " ")
|
||||
log.Print("D! [logrus] ", msg)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*LogHook) Levels() []logrus.Level {
|
||||
return logrus.AllLevels
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue