aboutsummaryrefslogtreecommitdiffstats
path: root/ethutil
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-02-19 23:27:22 +0800
committerobscuren <geffobscura@gmail.com>2014-02-19 23:27:22 +0800
commitd4cc125456c2531f133aaac6ea73d5decbb80dc4 (patch)
tree61d188f855a63797745540db4c187d694e7a54a3 /ethutil
parentdc994b35189950a15fc5397b7f17cda2ba62e0c3 (diff)
downloaddexon-d4cc125456c2531f133aaac6ea73d5decbb80dc4.tar.gz
dexon-d4cc125456c2531f133aaac6ea73d5decbb80dc4.tar.zst
dexon-d4cc125456c2531f133aaac6ea73d5decbb80dc4.zip
Added more logging functions
Diffstat (limited to 'ethutil')
-rw-r--r--ethutil/config.go37
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
}