diff options
author | Jakob Unterwurzacher | 2016-01-31 18:09:39 +0100 |
---|---|---|
committer | Jakob Unterwurzacher | 2016-01-31 18:09:39 +0100 |
commit | 6454db68d97667f90ec1f0f838c7da275c46d2b8 (patch) | |
tree | 8e7078f815a74c78f0c620723903e1ef1e88d0d3 /cryptfs/log.go | |
parent | 4c9e249e3ac1fc2995e01eb1ed24799c3a3bc66b (diff) |
Add new "-wpanic" option and enable it for the automated tests
Diffstat (limited to 'cryptfs/log.go')
-rw-r--r-- | cryptfs/log.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/cryptfs/log.go b/cryptfs/log.go index 44cb84f..19d8b51 100644 --- a/cryptfs/log.go +++ b/cryptfs/log.go @@ -2,6 +2,7 @@ package cryptfs import ( "encoding/json" + "fmt" "log" "os" ) @@ -17,7 +18,10 @@ func JSONDump(obj interface{}) string { // toggledLogger - a Logger than can be enabled and disabled type toggledLogger struct { + // Enable or disable output Enabled bool + // Panic after logging a message, useful in regression tests + PanicAfter bool *log.Logger } @@ -26,12 +30,18 @@ func (l *toggledLogger) Printf(format string, v ...interface{}) { return } l.Logger.Printf(format, v...) + if l.PanicAfter { + panic("PanicAfter: " + fmt.Sprintf(format, v...)) + } } func (l *toggledLogger) Println(v ...interface{}) { if !l.Enabled { return } l.Logger.Println(v...) + if l.PanicAfter { + panic("PanicAfter: " + fmt.Sprintln(v...)) + } } // As defined by http://elinux.org/Debugging_by_printing#Log_Levels @@ -45,7 +55,7 @@ var Info *toggledLogger var Warn *toggledLogger func init() { - Debug = &toggledLogger{false, log.New(os.Stdout, "", 0)} - Info = &toggledLogger{true, log.New(os.Stdout, "", 0)} - Warn = &toggledLogger{true, log.New(os.Stderr, "", 0)} + Debug = &toggledLogger{false, false, log.New(os.Stdout, "", 0)} + Info = &toggledLogger{true, false, log.New(os.Stdout, "", 0)} + Warn = &toggledLogger{true, false, log.New(os.Stderr, "", 0)} } |