diff options
author | 2018-11-15 22:18:49 +0000 | |
---|---|---|
committer | 2018-11-15 22:18:49 +0000 | |
commit | 3f6dfba1f0e9cd6c858f88891550d09904b7814d (patch) | |
tree | 04fdb7cf24fef14fcd347ab6a7e13a1144d28774 /plugin/pkg/log/plugin.go | |
parent | 669b99d91c5eaf4c669d03436083c98e3c298367 (diff) | |
download | coredns-3f6dfba1f0e9cd6c858f88891550d09904b7814d.tar.gz coredns-3f6dfba1f0e9cd6c858f88891550d09904b7814d.tar.zst coredns-3f6dfba1f0e9cd6c858f88891550d09904b7814d.zip |
Redo the plugin log PR (#2315)
* Redo the plugin log PR
Remove the code duplication and call of the "official" functions. This
is the second(?) time we forgot to update the other half, so remove that
problem entirely.
Also add a test if the correct (within limits) time in front of the log
line.
Signed-off-by: Miek Gieben <miek@miek.nl>
* Remove pFormat
Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin/pkg/log/plugin.go')
-rw-r--r-- | plugin/pkg/log/plugin.go | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/plugin/pkg/log/plugin.go b/plugin/pkg/log/plugin.go index 1df302609..0cc5f881a 100644 --- a/plugin/pkg/log/plugin.go +++ b/plugin/pkg/log/plugin.go @@ -2,7 +2,6 @@ package log import ( "fmt" - golog "log" "os" ) @@ -13,16 +12,14 @@ type P struct { // NewWithPlugin returns a logger that includes "plugin/name: " in the log message. // I.e [INFO] plugin/<name>: message. -func NewWithPlugin(name string) P { return P{name} } +func NewWithPlugin(name string) P { return P{"plugin/" + name + ": "} } func (p P) logf(level, format string, v ...interface{}) { - s := level + pFormat(p.plugin) + fmt.Sprintf(format, v...) - golog.Print(s) + log(level, p.plugin, fmt.Sprintf(format, v...)) } func (p P) log(level string, v ...interface{}) { - s := level + pFormat(p.plugin) + fmt.Sprint(v...) - golog.Print(s) + log(level+p.plugin, v...) } // Debug logs as log.Debug. @@ -64,5 +61,3 @@ func (p P) Fatal(v ...interface{}) { p.log(fatal, v...); os.Exit(1) } // Fatalf logs as log.Fatalf and calls os.Exit(1). func (p P) Fatalf(format string, v ...interface{}) { p.logf(fatal, format, v...); os.Exit(1) } - -func pFormat(s string) string { return "plugin/" + s + ": " } |