diff options
author | 2018-07-20 15:08:06 +0100 | |
---|---|---|
committer | 2018-07-20 15:08:06 +0100 | |
commit | 547f15546563c9d8bb520218cd3c9161394d9d20 (patch) | |
tree | 960ba94feff8c8dfd33213e203baff706f6bea35 | |
parent | d998aa6c25ffe83e2d2abf9ba52c5ada57da7e30 (diff) | |
download | coredns-547f15546563c9d8bb520218cd3c9161394d9d20.tar.gz coredns-547f15546563c9d8bb520218cd3c9161394d9d20.tar.zst coredns-547f15546563c9d8bb520218cd3c9161394d9d20.zip |
Logfatalf (#1990)
* bliep
Signed-off-by: Miek Gieben <miek@miek.nl>
* plugin/log: add log.Fatal[f]
Add log.Fatal(f) to mimic more of the log package. The first and only
use is in the (new) loop plugin.
Signed-off-by: Miek Gieben <miek@miek.nl>
-rw-r--r-- | plugin/pkg/log/log.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/plugin/pkg/log/log.go b/plugin/pkg/log/log.go index 387d7f8e2..f05dce03a 100644 --- a/plugin/pkg/log/log.go +++ b/plugin/pkg/log/log.go @@ -12,6 +12,7 @@ import ( "fmt" "io/ioutil" golog "log" + "os" ) // D controls whether we should output debug logs. If true, we do. @@ -62,12 +63,21 @@ func Error(v ...interface{}) { log(err, v...) } // Errorf is equivalent to log.Printf, but prefixed with "[ERROR] ". func Errorf(format string, v ...interface{}) { logf(err, format, v...) } +// Fatal is equivalent to log.Print, but prefixed with "[FATAL] ", and calling +// os.Exit(1). +func Fatal(v ...interface{}) { log(fatal, v...); os.Exit(1) } + +// Fatalf is equivalent to log.Printf, but prefixed with "[FATAL] ", and calling +// os.Exit(1) +func Fatalf(format string, v ...interface{}) { logf(fatal, format, v...); os.Exit(1) } + // Discard sets the log output to /dev/null. func Discard() { golog.SetOutput(ioutil.Discard) } const ( debug = "[DEBUG] " err = "[ERROR] " - warning = "[WARNING] " + fatal = "[FATAL] " info = "[INFO] " + warning = "[WARNING] " ) |