diff options
author | Andrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu> | 2012-05-16 23:57:26 -0400 |
---|---|---|
committer | Andrew Gallant (Ocelot) <Andrew.Gallant@tufts.edu> | 2012-05-16 23:57:26 -0400 |
commit | acb84171e55d46dc1a5b9cc10b2bff53c2d2846b (patch) | |
tree | a318f368d75796fd8d70208523663dcdcdf89b28 /nexgb/log.go | |
parent | 424f293671b256bb5e253eea1cbb83519f4243f3 (diff) | |
download | haven-acb84171e55d46dc1a5b9cc10b2bff53c2d2846b.tar.gz haven-acb84171e55d46dc1a5b9cc10b2bff53c2d2846b.tar.xz haven-acb84171e55d46dc1a5b9cc10b2bff53c2d2846b.zip |
Add new logger type so that it can be shut off.
Diffstat (limited to 'nexgb/log.go')
-rw-r--r-- | nexgb/log.go | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/nexgb/log.go b/nexgb/log.go new file mode 100644 index 0000000..eaaa57e --- /dev/null +++ b/nexgb/log.go @@ -0,0 +1,85 @@ +package xgb + +import ( + "log" + "os" +) + +// Log controls whether XGB emits errors to stderr. By default, it is enabled. +var PrintLog = true + +// log is a wrapper around a log.PrintLogger so we can control whether it should +// output anything. +type xgblog struct { + *log.Logger +} + +func newLogger() xgblog { + return xgblog{log.New(os.Stderr, "XGB: ", log.Lshortfile)} +} + +func (lg xgblog) Print(v ...interface{}) { + if PrintLog { + lg.Logger.Print(v...) + } +} + +func (lg xgblog) Printf(format string, v ...interface{}) { + if PrintLog { + lg.Logger.Printf(format, v...) + } +} + +func (lg xgblog) Println(v ...interface{}) { + if PrintLog { + lg.Logger.Println(v...) + } +} + +func (lg xgblog) Fatal(v ...interface{}) { + if PrintLog { + lg.Logger.Fatal(v...) + } else { + os.Exit(1) + } +} + +func (lg xgblog) Fatalf(format string, v ...interface{}) { + if PrintLog { + lg.Logger.Fatalf(format, v...) + } else { + os.Exit(1) + } +} + +func (lg xgblog) Fatalln(v ...interface{}) { + if PrintLog { + lg.Logger.Fatalln(v...) + } else { + os.Exit(1) + } +} + +func (lg xgblog) Panic(v ...interface{}) { + if PrintLog { + lg.Logger.Panic(v...) + } else { + panic("") + } +} + +func (lg xgblog) Panicf(format string, v ...interface{}) { + if PrintLog { + lg.Logger.Panicf(format, v...) + } else { + panic("") + } +} + +func (lg xgblog) Panicln(v ...interface{}) { + if PrintLog { + lg.Logger.Panicln(v...) + } else { + panic("") + } +} |