@ -15,6 +15,7 @@
package log
import (
"fmt"
"io"
"log"
"os"
@ -28,31 +29,34 @@ var (
// Init initializes settings related to logging
func Init ( debugFlag bool , out io . Writer ) {
debug = debugFlag
if debug {
airshipLog . SetFlags ( log . LstdFlags | log . Llongfile )
}
airshipLog . SetOutput ( out )
}
// Debug is a wrapper for log.Debug
func Debug ( v ... interface { } ) {
if debug {
airshipLog . Print ( v ... )
writeLog ( v ... )
}
}
// Debugf is a wrapper for log.Debugf
func Debugf ( format string , v ... interface { } ) {
if debug {
airshipLog . P rintf( format , v ... )
writeLog ( fmt . Sp rintf( format , v ... ) )
}
}
// Print is a wrapper for log.Print
func Print ( v ... interface { } ) {
airshipLog . Print ( v ... )
writeLog ( v ... )
}
// Printf is a wrapper for log.Printf
func Printf ( format string , v ... interface { } ) {
airshipLog . P rintf( format , v ... )
writeLog ( fmt . Sp rintf( format , v ... ) )
}
// Fatal is a wrapper for log.Fatal
@ -69,3 +73,15 @@ func Fatalf(format string, v ...interface{}) {
func Writer ( ) io . Writer {
return airshipLog . Writer ( )
}
func writeLog ( v ... interface { } ) {
if debug {
err := airshipLog . Output ( 3 , fmt . Sprint ( v ... ) )
if err != nil {
log . Print ( v ... )
log . Print ( err )
}
} else {
airshipLog . Print ( v ... )
}
}