diff options
author | obscuren <geffobscura@gmail.com> | 2014-02-19 23:27:22 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-02-19 23:27:22 +0800 |
commit | d4cc125456c2531f133aaac6ea73d5decbb80dc4 (patch) | |
tree | 61d188f855a63797745540db4c187d694e7a54a3 /ethutil | |
parent | dc994b35189950a15fc5397b7f17cda2ba62e0c3 (diff) | |
download | go-tangerine-d4cc125456c2531f133aaac6ea73d5decbb80dc4.tar.gz go-tangerine-d4cc125456c2531f133aaac6ea73d5decbb80dc4.tar.zst go-tangerine-d4cc125456c2531f133aaac6ea73d5decbb80dc4.zip |
Added more logging functions
Diffstat (limited to 'ethutil')
-rw-r--r-- | ethutil/config.go | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/ethutil/config.go b/ethutil/config.go index e61c347de..607152b5b 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -46,7 +46,7 @@ func ReadConfig(base string) *config { } Config = &config{ExecPath: path, Debug: true, Ver: "0.2.3"} - Config.Log = NewLogger(LogFile|LogStd, 0) + Config.Log = NewLogger(LogFile|LogStd, LogLevelDebug) } return Config @@ -67,7 +67,7 @@ type Logger struct { func NewLogger(flag LoggerType, level int) Logger { var loggers []*log.Logger - flags := log.LstdFlags | log.Lshortfile + flags := log.LstdFlags if flag&LogFile > 0 { file, err := os.OpenFile(path.Join(Config.ExecPath, "debug.log"), os.O_RDWR|os.O_CREATE|os.O_APPEND, os.ModePerm) @@ -75,20 +75,25 @@ func NewLogger(flag LoggerType, level int) Logger { log.Panic("unable to create file logger", err) } - log := log.New(file, "[ETH]", flags) + log := log.New(file, "", flags) loggers = append(loggers, log) } if flag&LogStd > 0 { - log := log.New(os.Stdout, "[ETH]", flags) + log := log.New(os.Stdout, "", flags) loggers = append(loggers, log) } return Logger{logSys: loggers, logLevel: level} } +const ( + LogLevelDebug = iota + LogLevelInfo +) + func (log Logger) Debugln(v ...interface{}) { - if log.logLevel != 0 { + if log.logLevel != LogLevelDebug { return } @@ -98,7 +103,27 @@ func (log Logger) Debugln(v ...interface{}) { } func (log Logger) Debugf(format string, v ...interface{}) { - if log.logLevel != 0 { + if log.logLevel != LogLevelDebug { + return + } + + for _, logger := range log.logSys { + logger.Printf(format, v...) + } +} + +func (log Logger) Infoln(v ...interface{}) { + if log.logLevel > LogLevelInfo { + return + } + + for _, logger := range log.logSys { + logger.Println(v...) + } +} + +func (log Logger) Infof(format string, v ...interface{}) { + if log.logLevel > LogLevelInfo { return } |