forked from BurntSushi/xgb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new logger type so that it can be shut off.
- Loading branch information
Andrew Gallant (Ocelot)
authored and
Andrew Gallant (Ocelot)
committed
May 17, 2012
1 parent
f4ec34d
commit cb3b697
Showing
3 changed files
with
100 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters