This isolates logging from the standard library
This commit adds a custom encapsulated Logger, which then has its methods exposed in a controlled fashion. This prevents external libraries from modifying things such as the flags passed to the logger, or where it should output to. Change-Id: Ide4321246b1277fcee51608aa95532b8696b9777
This commit is contained in:
parent
dc9c78b210
commit
062f59119f
@ -3,46 +3,50 @@ package log
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var debug = false
|
||||
var (
|
||||
debug = false
|
||||
airshipLog = log.New(os.Stderr, "", log.LstdFlags)
|
||||
)
|
||||
|
||||
// Init initializes settings related to logging
|
||||
func Init(debugFlag bool, out io.Writer) {
|
||||
debug = debugFlag
|
||||
log.SetOutput(out)
|
||||
airshipLog.SetOutput(out)
|
||||
}
|
||||
|
||||
// Debug is a wrapper for log.Debug
|
||||
func Debug(v ...interface{}) {
|
||||
if debug {
|
||||
log.Print(v...)
|
||||
airshipLog.Print(v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Debugf is a wrapper for log.Debugf
|
||||
func Debugf(format string, v ...interface{}) {
|
||||
if debug {
|
||||
log.Printf(format, v...)
|
||||
airshipLog.Printf(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
// Print is a wrapper for log.Print
|
||||
func Print(v ...interface{}) {
|
||||
log.Print(v...)
|
||||
airshipLog.Print(v...)
|
||||
}
|
||||
|
||||
// Printf is a wrapper for log.Printf
|
||||
func Printf(format string, v ...interface{}) {
|
||||
log.Printf(format, v...)
|
||||
airshipLog.Printf(format, v...)
|
||||
}
|
||||
|
||||
// Fatal is a wrapper for log.Fatal
|
||||
func Fatal(v ...interface{}) {
|
||||
log.Fatal(v...)
|
||||
airshipLog.Fatal(v...)
|
||||
}
|
||||
|
||||
// Fatalf is a wrapper for log.Fatalf
|
||||
func Fatalf(format string, v ...interface{}) {
|
||||
log.Fatalf(format, v...)
|
||||
airshipLog.Fatalf(format, v...)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user