diff --git a/log/logger.go b/log/logger.go index 479d68e3b3e18e951f20bfc5e8aa8903158f1f61..9694aabe4ac0175bffc2cc424bf8b9cc782f4545 100644 --- a/log/logger.go +++ b/log/logger.go @@ -58,8 +58,8 @@ func get() *Logger { return logger } -//Loglevel sets the verbosity of the logger -//Defaults to INFO +// Loglevel sets the verbosity of the logger +// Defaults to INFO func Loglevel(level Level) { l := get() l.lock.Lock() @@ -67,8 +67,8 @@ func Loglevel(level Level) { l.Loglevel = level } -//Output defines the output of the logger -//Defaults to os.Stderr +// Output defines the output of the logger +// Defaults to os.Stderr func Output(out io.Writer) { l := get() l.lock.Lock() @@ -76,8 +76,8 @@ func Output(out io.Writer) { l.DefaultWriter = out } -//LoglevelOutput defines a special output -//for a certain log level +// LoglevelOutput defines a special output +// for a certain log level func LoglevelOutput(level Level, out io.Writer) { l := get() l.lock.Lock() @@ -88,44 +88,77 @@ func LoglevelOutput(level Level, out io.Writer) { } } -//Debug passes the DEBUG flag and a -//message to the logger +// Debug passes the DEBUG flag and a +// message to the logger func Debug(args ...interface{}) { log(DEBUG, args...) } -//Info passes the INFO flag and a -//message to the logger +// Info passes the INFO flag and a +// message to the logger func Info(args ...interface{}) { log(INFO, args...) } -//Warn passes the WARNING flag and a -//message to the logger +// Warn passes the WARNING flag and a +// message to the logger func Warn(args ...interface{}) { log(WARNING, args...) } -//Error passes the ERROR flag and a -//message to the logger +// Error passes the ERROR flag and a +// message to the logger func Error(args ...interface{}) { log(ERROR, args...) } -//Fatal passes the FATAL flag and a -//message to the logger and calls -//os.Exit(1) +// Fatal passes the FATAL flag and a +// message to the logger and calls +// os.Exit(1) func Fatal(args ...interface{}) { log(FATAL, args...) os.Exit(1) } -//Panic passes the PANIC flag and a -//message to the logger -//Also calls builtin.panic() -func Panic(args ...interface{}) { - log(PANIC, args...) - panic(args) +// Debugf passes the DEBUG flag, +// a formatted string and a +// message to the logger +func Debugf(format string, args ...interface{}) { + logf(DEBUG, format, args...) +} + +// Infof passes the INFO flag, +// a formatted string and and a +// message to the logger +func Infof(format string, args ...interface{}) { + logf(INFO, format, args...) +} + +// Warnf passes the WARNING flag, +// a formatted string and and a +// message to the logger +func Warnf(format string, args ...interface{}) { + logf(WARNING, format, args...) +} + +// Errorf passes the ERROR flag, +// a formatted string and and a +// message to the logger +func Errorf(format string, args ...interface{}) { + logf(ERROR, format, args...) +} + +// Fatalf passes the FATAL flag, +// a formatted string and and a +// message to the logger and calls +// os.Exit(1) +func Fatalf(format string, args ...interface{}) { + logf(FATAL, format, args...) + os.Exit(1) +} + +func logf(level Level, format string, args ...interface{}) { + log(level, fmt.Sprintf(format, args...)) } func log(level Level, args ...interface{}) { @@ -164,8 +197,6 @@ func callers() (string, int) { func prefix(level Level) string { switch level { - case PANIC: - return "PANIC" case FATAL: return "FATAL" case ERROR: diff --git a/log/loglevel.go b/log/loglevel.go index 6288bcbc97b5843f346565bfe753e78aff7579cc..377e454b6c5e23b7f27fa970a28f456cd05bd33c 100644 --- a/log/loglevel.go +++ b/log/loglevel.go @@ -7,8 +7,7 @@ type Level uint8 // Constants for more verbose integer // values const ( - PANIC Level = iota - FATAL + FATAL Level = iota ERROR WARNING INFO