forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve ipvs input error strings and logging (influxdata#6530)
- Loading branch information
1 parent
0b31e35
commit 13085dd
Showing
3 changed files
with
44 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package logrus | ||
|
||
import ( | ||
"io/ioutil" | ||
"log" | ||
"strings" | ||
"sync" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
var once sync.Once | ||
|
||
type LogHook struct { | ||
} | ||
|
||
// Install 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(ioutil.Discard) | ||
logrus.AddHook(&LogHook{}) | ||
}) | ||
} | ||
|
||
func (h *LogHook) Fire(entry *logrus.Entry) error { | ||
msg := strings.ReplaceAll(entry.Message, "\n", " ") | ||
log.Print("D! [logrus] ", msg) | ||
return nil | ||
} | ||
|
||
func (h *LogHook) Levels() []logrus.Level { | ||
return logrus.AllLevels | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters