Commit 547f1554 authored by Miek Gieben's avatar Miek Gieben Committed by GitHub

Logfatalf (#1990)

* bliep
Signed-off-by: default avatarMiek 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: default avatarMiek Gieben <miek@miek.nl>
parent d998aa6c
...@@ -12,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
golog "log" golog "log"
"os"
) )
// D controls whether we should output debug logs. If true, we do. // D controls whether we should output debug logs. If true, we do.
...@@ -62,12 +63,21 @@ func Error(v ...interface{}) { log(err, v...) } ...@@ -62,12 +63,21 @@ func Error(v ...interface{}) { log(err, v...) }
// Errorf is equivalent to log.Printf, but prefixed with "[ERROR] ". // Errorf is equivalent to log.Printf, but prefixed with "[ERROR] ".
func Errorf(format string, v ...interface{}) { logf(err, format, v...) } 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. // Discard sets the log output to /dev/null.
func Discard() { golog.SetOutput(ioutil.Discard) } func Discard() { golog.SetOutput(ioutil.Discard) }
const ( const (
debug = "[DEBUG] " debug = "[DEBUG] "
err = "[ERROR] " err = "[ERROR] "
warning = "[WARNING] " fatal = "[FATAL] "
info = "[INFO] " info = "[INFO] "
warning = "[WARNING] "
) )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment