From f6d1bfe45bf3709d7bad40bf563b5c09228622e3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 14 Feb 2014 23:56:09 +0100 Subject: The great merge --- ethutil/config.go | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 ethutil/config.go (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go new file mode 100644 index 000000000..7782e7daa --- /dev/null +++ b/ethutil/config.go @@ -0,0 +1,106 @@ +package ethutil + +import ( + "log" + "os" + "os/user" + "path" +) + +type LogType byte + +const ( + LogTypeStdIn = 1 + LogTypeFile = 2 +) + +// Config struct isn't exposed +type config struct { + Db Database + + Log Logger + ExecPath string + Debug bool + Ver string + Pubkey []byte + Seed bool +} + +var Config *config + +// Read config doesn't read anything yet. +func ReadConfig(base string) *config { + if Config == nil { + usr, _ := user.Current() + path := path.Join(usr.HomeDir, base) + + //Check if the logging directory already exists, create it if not + _, err := os.Stat(path) + if err != nil { + if os.IsNotExist(err) { + log.Printf("Debug logging directory %s doesn't exist, creating it", path) + os.Mkdir(path, 0777) + } + } + + Config = &config{ExecPath: path, Debug: true, Ver: "0.2.1"} + Config.Log = NewLogger(LogFile|LogStd, 0) + } + + return Config +} + +type LoggerType byte + +const ( + LogFile = 0x1 + LogStd = 0x2 +) + +type Logger struct { + logSys []*log.Logger + logLevel int +} + +func NewLogger(flag LoggerType, level int) Logger { + var loggers []*log.Logger + + flags := log.LstdFlags | log.Lshortfile + + 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) + if err != nil { + log.Panic("unable to create file logger", err) + } + + log := log.New(file, "[ETH]", flags) + + loggers = append(loggers, log) + } + if flag&LogStd > 0 { + log := log.New(os.Stdout, "[ETH]", flags) + loggers = append(loggers, log) + } + + return Logger{logSys: loggers, logLevel: level} +} + +func (log Logger) Debugln(v ...interface{}) { + if log.logLevel != 0 { + return + } + + for _, logger := range log.logSys { + logger.Println(v...) + } +} + +func (log Logger) Debugf(format string, v ...interface{}) { + if log.logLevel != 0 { + return + } + + for _, logger := range log.logSys { + logger.Printf(format, v...) + } +} -- cgit v1.2.3 From fd1aa869e1544fd4d867b8f5a51985e01b692b0d Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 15 Feb 2014 11:52:28 +0100 Subject: Bumped version number --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 7782e7daa..2a239f8e2 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -43,7 +43,7 @@ func ReadConfig(base string) *config { } } - Config = &config{ExecPath: path, Debug: true, Ver: "0.2.1"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.2.2"} Config.Log = NewLogger(LogFile|LogStd, 0) } -- cgit v1.2.3 From c5b009ba6f153aa65fa25126bea41d899a436299 Mon Sep 17 00:00:00 2001 From: Joey Zhou Date: Mon, 17 Feb 2014 15:47:33 -0800 Subject: new line --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 2a239f8e2..b361a3079 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -38,7 +38,7 @@ func ReadConfig(base string) *config { _, err := os.Stat(path) if err != nil { if os.IsNotExist(err) { - log.Printf("Debug logging directory %s doesn't exist, creating it", path) + log.Printf("Debug logging directory %s doesn't exist, creating it\n", path) os.Mkdir(path, 0777) } } -- cgit v1.2.3 From c866fcc5b37b53e0d11c1fd7e6cb971859537f2c Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 18 Feb 2014 12:10:21 +0100 Subject: Added new address --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 2a239f8e2..df1772d81 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -43,7 +43,7 @@ func ReadConfig(base string) *config { } } - Config = &config{ExecPath: path, Debug: true, Ver: "0.2.2"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.2.3"} Config.Log = NewLogger(LogFile|LogStd, 0) } -- cgit v1.2.3 From 24f2b2afc3a848190822c382e6aa31c8ab120f07 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 19 Feb 2014 11:35:17 +0100 Subject: Running contracts fixed --- ethutil/config.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index df1772d81..70553fb5b 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -34,12 +34,14 @@ func ReadConfig(base string) *config { usr, _ := user.Current() path := path.Join(usr.HomeDir, base) - //Check if the logging directory already exists, create it if not - _, err := os.Stat(path) - if err != nil { - if os.IsNotExist(err) { - log.Printf("Debug logging directory %s doesn't exist, creating it", path) - os.Mkdir(path, 0777) + if len(base) > 0 { + //Check if the logging directory already exists, create it if not + _, err := os.Stat(path) + if err != nil { + if os.IsNotExist(err) { + log.Printf("Debug logging directory %s doesn't exist, creating it", path) + os.Mkdir(path, 0777) + } } } -- cgit v1.2.3 From d4cc125456c2531f133aaac6ea73d5decbb80dc4 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 19 Feb 2014 16:27:22 +0100 Subject: Added more logging functions --- ethutil/config.go | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'ethutil/config.go') 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 } -- cgit v1.2.3 From 4bfd717ba2b753f183e9e3fecd91d7e4083aaffc Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 22 Feb 2014 01:53:09 +0100 Subject: Added the ability to extend the logger with more sub systems --- ethutil/config.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 607152b5b..5bf56134d 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -1,6 +1,7 @@ package ethutil import ( + "fmt" "log" "os" "os/user" @@ -18,7 +19,7 @@ const ( type config struct { Db Database - Log Logger + Log *Logger ExecPath string Debug bool Ver string @@ -45,7 +46,7 @@ func ReadConfig(base string) *config { } } - Config = &config{ExecPath: path, Debug: true, Ver: "0.2.3"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.3.0"} Config.Log = NewLogger(LogFile|LogStd, LogLevelDebug) } @@ -59,13 +60,18 @@ const ( LogStd = 0x2 ) +type LogSystem interface { + Println(v ...interface{}) + Printf(format string, v ...interface{}) +} + type Logger struct { - logSys []*log.Logger + logSys []LogSystem logLevel int } -func NewLogger(flag LoggerType, level int) Logger { - var loggers []*log.Logger +func NewLogger(flag LoggerType, level int) *Logger { + var loggers []LogSystem flags := log.LstdFlags @@ -84,7 +90,11 @@ func NewLogger(flag LoggerType, level int) Logger { loggers = append(loggers, log) } - return Logger{logSys: loggers, logLevel: level} + return &Logger{logSys: loggers, logLevel: level} +} + +func (log *Logger) AddLogSystem(logger LogSystem) { + log.logSys = append(log.logSys, logger) } const ( @@ -92,7 +102,7 @@ const ( LogLevelInfo ) -func (log Logger) Debugln(v ...interface{}) { +func (log *Logger) Debugln(v ...interface{}) { if log.logLevel != LogLevelDebug { return } @@ -102,7 +112,7 @@ func (log Logger) Debugln(v ...interface{}) { } } -func (log Logger) Debugf(format string, v ...interface{}) { +func (log *Logger) Debugf(format string, v ...interface{}) { if log.logLevel != LogLevelDebug { return } @@ -112,17 +122,18 @@ func (log Logger) Debugf(format string, v ...interface{}) { } } -func (log Logger) Infoln(v ...interface{}) { +func (log *Logger) Infoln(v ...interface{}) { if log.logLevel > LogLevelInfo { return } + fmt.Println(len(log.logSys)) for _, logger := range log.logSys { logger.Println(v...) } } -func (log Logger) Infof(format string, v ...interface{}) { +func (log *Logger) Infof(format string, v ...interface{}) { if log.logLevel > LogLevelInfo { return } -- cgit v1.2.3 From b462ca4aade75049a0fcba23c54e340f0f793dfb Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 28 Feb 2014 16:45:46 +0100 Subject: Bump --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 5bf56134d..5fdc8e1c5 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.3.0"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.3.1"} Config.Log = NewLogger(LogFile|LogStd, LogLevelDebug) } -- cgit v1.2.3 From 344e827061c896a17124a65686bdc3fbbd03d7bb Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 17 Mar 2014 12:08:16 +0100 Subject: Added client string to configuration Clients can set their own client string which will be send to connected peers during the handshake. --- ethutil/config.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 5fdc8e1c5..436c12b92 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -6,6 +6,7 @@ import ( "os" "os/user" "path" + "runtime" ) type LogType byte @@ -19,12 +20,13 @@ const ( type config struct { Db Database - Log *Logger - ExecPath string - Debug bool - Ver string - Pubkey []byte - Seed bool + Log *Logger + ExecPath string + Debug bool + Ver string + ClientString string + Pubkey []byte + Seed bool } var Config *config @@ -48,6 +50,7 @@ func ReadConfig(base string) *config { Config = &config{ExecPath: path, Debug: true, Ver: "0.3.1"} Config.Log = NewLogger(LogFile|LogStd, LogLevelDebug) + Config.ClientString = fmt.Sprintf("/Ethereum(G) v%s/%s", Config.Ver, runtime.GOOS) } return Config -- cgit v1.2.3 From f21eb88ad1cf54b342187e8d3b55374a695cd524 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 20 Mar 2014 17:27:48 +0100 Subject: Some minor updates --- ethutil/config.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 436c12b92..54b066fb9 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -50,12 +50,16 @@ func ReadConfig(base string) *config { Config = &config{ExecPath: path, Debug: true, Ver: "0.3.1"} Config.Log = NewLogger(LogFile|LogStd, LogLevelDebug) - Config.ClientString = fmt.Sprintf("/Ethereum(G) v%s/%s", Config.Ver, runtime.GOOS) + Config.SetClientString("/Ethereum(G)") } return Config } +func (c *config) SetClientString(str string) { + Config.ClientString = fmt.Sprintf("%s nv%s/%s", str, c.Ver, runtime.GOOS) +} + type LoggerType byte const ( -- cgit v1.2.3 From 16e52327a4baa5547c38965fce53b3ff40b98173 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 27 Apr 2014 16:50:44 +0200 Subject: Upped version number --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 54b066fb9..86c0a855d 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -48,7 +48,7 @@ func ReadConfig(base string) *config { } } - Config = &config{ExecPath: path, Debug: true, Ver: "0.3.1"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5"} Config.Log = NewLogger(LogFile|LogStd, LogLevelDebug) Config.SetClientString("/Ethereum(G)") } -- cgit v1.2.3 From 338b6980915c990c6e6287a7249ddd98e6be20eb Mon Sep 17 00:00:00 2001 From: obscuren Date: Sun, 27 Apr 2014 17:15:44 +0200 Subject: Refactoring and added documentation comments --- ethutil/config.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 86c0a855d..323773ba7 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -9,6 +9,7 @@ import ( "runtime" ) +// Log types available type LogType byte const ( @@ -16,7 +17,7 @@ const ( LogTypeFile = 2 ) -// Config struct isn't exposed +// Config struct type config struct { Db Database @@ -31,7 +32,9 @@ type config struct { var Config *config -// Read config doesn't read anything yet. +// Read config +// +// Initialize the global Config variable with default settings func ReadConfig(base string) *config { if Config == nil { usr, _ := user.Current() @@ -56,6 +59,8 @@ func ReadConfig(base string) *config { return Config } +// Set client string +// func (c *config) SetClientString(str string) { Config.ClientString = fmt.Sprintf("%s nv%s/%s", str, c.Ver, runtime.GOOS) } -- cgit v1.2.3 From 9b1f11695d544b99ba0b7ddedc4ac561a68d8197 Mon Sep 17 00:00:00 2001 From: Maran Date: Mon, 5 May 2014 14:20:20 +0200 Subject: Get rid of that annoying number that keeps popping up in stdout --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 323773ba7..609200649 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -139,7 +139,7 @@ func (log *Logger) Infoln(v ...interface{}) { return } - fmt.Println(len(log.logSys)) + //fmt.Println(len(log.logSys)) for _, logger := range log.logSys { logger.Println(v...) } -- cgit v1.2.3 From fedd4c906ff9f6139cb2d88e4f1adefbf6ea81a6 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 5 May 2014 15:55:26 +0200 Subject: bump --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 609200649..382396ceb 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -51,7 +51,7 @@ func ReadConfig(base string) *config { } } - Config = &config{ExecPath: path, Debug: true, Ver: "0.5"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5 RC1"} Config.Log = NewLogger(LogFile|LogStd, LogLevelDebug) Config.SetClientString("/Ethereum(G)") } -- cgit v1.2.3 From afe83af219c2146e022f6665cf30097b582d3e79 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 9 May 2014 16:09:28 +0200 Subject: Moved seeding and moved manifest --- ethutil/config.go | 1 - 1 file changed, 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 382396ceb..db07e1d18 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -27,7 +27,6 @@ type config struct { Ver string ClientString string Pubkey []byte - Seed bool } var Config *config -- cgit v1.2.3 From dbf8645aafb19837d01b939ba9b1d3e1a2fffbf9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 10 May 2014 02:02:54 +0200 Subject: Bump --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index db07e1d18..5e36b06d2 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -50,7 +50,7 @@ func ReadConfig(base string) *config { } } - Config = &config{ExecPath: path, Debug: true, Ver: "0.5 RC1"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC2"} Config.Log = NewLogger(LogFile|LogStd, LogLevelDebug) Config.SetClientString("/Ethereum(G)") } -- cgit v1.2.3 From d3d9ed62e26247c680e23a94fd84b078d45cb3bc Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 10 May 2014 16:23:07 +0200 Subject: Upgraded to new mutan --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 5e36b06d2..feab23e02 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -50,7 +50,7 @@ func ReadConfig(base string) *config { } } - Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC2"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC3"} Config.Log = NewLogger(LogFile|LogStd, LogLevelDebug) Config.SetClientString("/Ethereum(G)") } -- cgit v1.2.3 From 86d6aba0127d6f35f5dda50d08dff05581031701 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 13 May 2014 16:36:43 +0200 Subject: Bumped --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index feab23e02..07dc85f08 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -50,7 +50,7 @@ func ReadConfig(base string) *config { } } - Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC3"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC4"} Config.Log = NewLogger(LogFile|LogStd, LogLevelDebug) Config.SetClientString("/Ethereum(G)") } -- cgit v1.2.3 From ad4ffdc9474aca48ab1d3d361797398f795a6d31 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 14 May 2014 21:34:13 +0200 Subject: Bumped version --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 07dc85f08..b4bd9158e 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -50,7 +50,7 @@ func ReadConfig(base string) *config { } } - Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC4"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC6"} Config.Log = NewLogger(LogFile|LogStd, LogLevelDebug) Config.SetClientString("/Ethereum(G)") } -- cgit v1.2.3 From 8730dfdcc2e2b40410a57385e4864d15f2f0336b Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 17 May 2014 14:07:52 +0200 Subject: Changed how changes are being applied to states --- ethutil/config.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index b4bd9158e..296b72d9e 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -9,14 +9,6 @@ import ( "runtime" ) -// Log types available -type LogType byte - -const ( - LogTypeStdIn = 1 - LogTypeFile = 2 -) - // Config struct type config struct { Db Database @@ -34,7 +26,7 @@ var Config *config // Read config // // Initialize the global Config variable with default settings -func ReadConfig(base string) *config { +func ReadConfig(base string, logTypes LoggerType) *config { if Config == nil { usr, _ := user.Current() path := path.Join(usr.HomeDir, base) @@ -51,7 +43,7 @@ func ReadConfig(base string) *config { } Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC6"} - Config.Log = NewLogger(LogFile|LogStd, LogLevelDebug) + Config.Log = NewLogger(logTypes, LogLevelDebug) Config.SetClientString("/Ethereum(G)") } -- cgit v1.2.3 From a2fb265563a3a6eb80efc5720bb0c6f3fec6f397 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 19 May 2014 17:02:16 +0200 Subject: Added a fatal method --- ethutil/config.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 296b72d9e..fd590fbdb 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -130,7 +130,6 @@ func (log *Logger) Infoln(v ...interface{}) { return } - //fmt.Println(len(log.logSys)) for _, logger := range log.logSys { logger.Println(v...) } @@ -145,3 +144,15 @@ func (log *Logger) Infof(format string, v ...interface{}) { logger.Printf(format, v...) } } + +func (log *Logger) Fatal(v ...interface{}) { + if log.logLevel > LogLevelInfo { + return + } + + for _, logger := range log.logSys { + logger.Println(v...) + } + + os.Exit(1) +} -- cgit v1.2.3 From c37b3cef7dc465832761b1da6761eeaa47e368d1 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 20 May 2014 17:08:53 +0200 Subject: Bump --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index fd590fbdb..abe86babe 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -42,7 +42,7 @@ func ReadConfig(base string, logTypes LoggerType) *config { } } - Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC6"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC7"} Config.Log = NewLogger(logTypes, LogLevelDebug) Config.SetClientString("/Ethereum(G)") } -- cgit v1.2.3 From 8f5eddd0ba9287cfcdc0e1f114c3fb367e54c46c Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 21 May 2014 14:04:19 +0200 Subject: Bumped --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index abe86babe..1b41c4634 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -42,7 +42,7 @@ func ReadConfig(base string, logTypes LoggerType) *config { } } - Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC7"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC8"} Config.Log = NewLogger(logTypes, LogLevelDebug) Config.SetClientString("/Ethereum(G)") } -- cgit v1.2.3 From 230aafbf66ba747fb3796810adf3b1680f368e73 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 22 May 2014 17:35:26 +0200 Subject: Working on interop * Receipts after each transaction * Fee structure * Applying fees to miners --- ethutil/config.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 1b41c4634..e6cbde4b6 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -19,6 +19,7 @@ type config struct { Ver string ClientString string Pubkey []byte + Identifier string } var Config *config @@ -26,7 +27,7 @@ var Config *config // Read config // // Initialize the global Config variable with default settings -func ReadConfig(base string, logTypes LoggerType) *config { +func ReadConfig(base string, logTypes LoggerType, id string) *config { if Config == nil { usr, _ := user.Current() path := path.Join(usr.HomeDir, base) @@ -43,6 +44,7 @@ func ReadConfig(base string, logTypes LoggerType) *config { } Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC8"} + Config.Identifier = id Config.Log = NewLogger(logTypes, LogLevelDebug) Config.SetClientString("/Ethereum(G)") } @@ -53,7 +55,11 @@ func ReadConfig(base string, logTypes LoggerType) *config { // Set client string // func (c *config) SetClientString(str string) { - Config.ClientString = fmt.Sprintf("%s nv%s/%s", str, c.Ver, runtime.GOOS) + id := runtime.GOOS + if len(c.Identifier) > 0 { + id = c.Identifier + } + Config.ClientString = fmt.Sprintf("%s nv%s/%s", str, c.Ver, id) } type LoggerType byte -- cgit v1.2.3 From 1f3f76cb092e84bd2e90950f0d43d7657eae878e Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 26 May 2014 00:38:53 +0200 Subject: bump --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index e6cbde4b6..40ab3aa69 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -43,7 +43,7 @@ func ReadConfig(base string, logTypes LoggerType, id string) *config { } } - Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC8"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC9"} Config.Identifier = id Config.Log = NewLogger(logTypes, LogLevelDebug) Config.SetClientString("/Ethereum(G)") -- cgit v1.2.3 From a4285331601d9d77458d0d714dd110144c796023 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 27 May 2014 16:10:18 +0200 Subject: bump --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 40ab3aa69..a7c318e52 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -43,7 +43,7 @@ func ReadConfig(base string, logTypes LoggerType, id string) *config { } } - Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC9"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC10"} Config.Identifier = id Config.Log = NewLogger(logTypes, LogLevelDebug) Config.SetClientString("/Ethereum(G)") -- cgit v1.2.3 From 76a59274bfce73ec988131804c643be743d2b4d2 Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 28 May 2014 16:19:25 +0200 Subject: Bump to RC11 --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index a7c318e52..fb270ce72 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -43,7 +43,7 @@ func ReadConfig(base string, logTypes LoggerType, id string) *config { } } - Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC10"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC11"} Config.Identifier = id Config.Log = NewLogger(logTypes, LogLevelDebug) Config.SetClientString("/Ethereum(G)") -- cgit v1.2.3 From 17c825f53a2676ffe17fd7731f8f550aebcb56b0 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 30 May 2014 16:57:58 +0200 Subject: Peer changes broadcasting and minor miner fix --- ethutil/config.go | 54 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 13 deletions(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index fb270ce72..916b0d186 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -22,26 +22,54 @@ type config struct { Identifier string } +const defaultConf = ` +id = "" +port = 30303 +upnp = true +maxpeer = 10 +rpc = false +rpcport = 8080 +` + var Config *config +func ApplicationFolder(base string) string { + usr, _ := user.Current() + p := path.Join(usr.HomeDir, base) + + if len(base) > 0 { + //Check if the logging directory already exists, create it if not + _, err := os.Stat(p) + if err != nil { + if os.IsNotExist(err) { + log.Printf("Debug logging directory %s doesn't exist, creating it\n", p) + os.Mkdir(p, 0777) + + } + } + + iniFilePath := path.Join(p, "conf.ini") + _, err = os.Stat(iniFilePath) + if err != nil && os.IsNotExist(err) { + file, err := os.Create(iniFilePath) + if err != nil { + fmt.Println(err) + } else { + assetPath := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "ethereal", "assets") + file.Write([]byte(defaultConf + "\nasset_path = " + assetPath)) + } + } + } + + return p +} + // Read config // // Initialize the global Config variable with default settings func ReadConfig(base string, logTypes LoggerType, id string) *config { if Config == nil { - usr, _ := user.Current() - path := path.Join(usr.HomeDir, base) - - if len(base) > 0 { - //Check if the logging directory already exists, create it if not - _, err := os.Stat(path) - if err != nil { - if os.IsNotExist(err) { - log.Printf("Debug logging directory %s doesn't exist, creating it\n", path) - os.Mkdir(path, 0777) - } - } - } + path := ApplicationFolder(base) Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC11"} Config.Identifier = id -- cgit v1.2.3 From 9e8127accba0d926436d3c0adf65b91149a94783 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 30 May 2014 19:51:19 +0200 Subject: woops --- ethutil/config.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 916b0d186..4f7820eed 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -1,7 +1,9 @@ package ethutil import ( + "flag" "fmt" + "github.com/rakyll/globalconf" "log" "os" "os/user" @@ -20,6 +22,8 @@ type config struct { ClientString string Pubkey []byte Identifier string + + conf *globalconf.GlobalConf } const defaultConf = ` @@ -67,11 +71,12 @@ func ApplicationFolder(base string) string { // Read config // // Initialize the global Config variable with default settings -func ReadConfig(base string, logTypes LoggerType, id string) *config { +func ReadConfig(base string, logTypes LoggerType, g *globalconf.GlobalConf, id string) *config { if Config == nil { path := ApplicationFolder(base) Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC11"} + Config.conf = g Config.Identifier = id Config.Log = NewLogger(logTypes, LogLevelDebug) Config.SetClientString("/Ethereum(G)") @@ -90,6 +95,16 @@ func (c *config) SetClientString(str string) { Config.ClientString = fmt.Sprintf("%s nv%s/%s", str, c.Ver, id) } +func (c *config) SetIdentifier(id string) { + c.Identifier = id + c.Set("id", id) +} + +func (c *config) Set(key, value string) { + f := &flag.Flag{Name: key, Value: &confValue{value}} + c.conf.Set("", f) +} + type LoggerType byte const ( @@ -190,3 +205,10 @@ func (log *Logger) Fatal(v ...interface{}) { os.Exit(1) } + +type confValue struct { + value string +} + +func (self confValue) String() string { return self.value } +func (self confValue) Set(s string) error { self.value = s; return nil } -- cgit v1.2.3 From a51dfe89c05cc12b4a8483f683ff9f49b3a8f1bd Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 9 Jun 2014 22:23:30 +0200 Subject: bump --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 4f7820eed..e992bda12 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -75,7 +75,7 @@ func ReadConfig(base string, logTypes LoggerType, g *globalconf.GlobalConf, id s if Config == nil { path := ApplicationFolder(base) - Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC11"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC12"} Config.conf = g Config.Identifier = id Config.Log = NewLogger(logTypes, LogLevelDebug) -- cgit v1.2.3 From 3a9d7d318abb3cd01ecd012ae85da5e586436d65 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 12 Jun 2014 10:07:27 +0200 Subject: log changes --- ethutil/config.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index e992bda12..f935e8f75 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -75,11 +75,11 @@ func ReadConfig(base string, logTypes LoggerType, g *globalconf.GlobalConf, id s if Config == nil { path := ApplicationFolder(base) - Config = &config{ExecPath: path, Debug: true, Ver: "0.5.0 RC12"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5.12"} Config.conf = g Config.Identifier = id Config.Log = NewLogger(logTypes, LogLevelDebug) - Config.SetClientString("/Ethereum(G)") + Config.SetClientString("Ethereum(G)") } return Config @@ -88,11 +88,9 @@ func ReadConfig(base string, logTypes LoggerType, g *globalconf.GlobalConf, id s // Set client string // func (c *config) SetClientString(str string) { - id := runtime.GOOS - if len(c.Identifier) > 0 { - id = c.Identifier - } - Config.ClientString = fmt.Sprintf("%s nv%s/%s", str, c.Ver, id) + os := runtime.GOOS + cust := c.Identifier + Config.ClientString = fmt.Sprintf("%s/v%s/%s/%s/Go", str, c.Ver, cust, os) } func (c *config) SetIdentifier(id string) { -- cgit v1.2.3 From 6d52da58d9337b786a0c869974daa91ce0e34a98 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 14 Jun 2014 15:44:13 +0200 Subject: Logging mechanism --- ethutil/config.go | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index f935e8f75..90037df87 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -143,12 +143,17 @@ func NewLogger(flag LoggerType, level int) *Logger { return &Logger{logSys: loggers, logLevel: level} } +func (self *Logger) SetLevel(level int) { + self.logLevel = level +} + func (log *Logger) AddLogSystem(logger LogSystem) { log.logSys = append(log.logSys, logger) } const ( - LogLevelDebug = iota + LogLevelSystem = iota + LogLevelDebug LogLevelInfo ) @@ -204,6 +209,26 @@ func (log *Logger) Fatal(v ...interface{}) { os.Exit(1) } +func (log *Logger) Println(level int, v ...interface{}) { + if log.logLevel > level { + return + } + + for _, logger := range log.logSys { + logger.Println(v...) + } +} + +func (log *Logger) Printf(level int, format string, v ...interface{}) { + if log.logLevel > level { + return + } + + for _, logger := range log.logSys { + logger.Printf(format, v...) + } +} + type confValue struct { value string } -- cgit v1.2.3 From ff0f15f7634ca713b0ce8232a8fa63eec5c3fad7 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 16 Jun 2014 18:25:21 +0200 Subject: bump --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 90037df87..a24c39bfe 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -75,7 +75,7 @@ func ReadConfig(base string, logTypes LoggerType, g *globalconf.GlobalConf, id s if Config == nil { path := ApplicationFolder(base) - Config = &config{ExecPath: path, Debug: true, Ver: "0.5.12"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5.13"} Config.conf = g Config.Identifier = id Config.Log = NewLogger(logTypes, LogLevelDebug) -- cgit v1.2.3 From 7ad073fb30e92689942d938939223bd01cb5fe38 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 20 Jun 2014 00:47:50 +0200 Subject: bump --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index a24c39bfe..a573e108b 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -75,7 +75,7 @@ func ReadConfig(base string, logTypes LoggerType, g *globalconf.GlobalConf, id s if Config == nil { path := ApplicationFolder(base) - Config = &config{ExecPath: path, Debug: true, Ver: "0.5.13"} + Config = &config{ExecPath: path, Debug: true, Ver: "0.5.14"} Config.conf = g Config.Identifier = id Config.Log = NewLogger(logTypes, LogLevelDebug) -- cgit v1.2.3 From 63157c798d613f1ca638597515bb89768e2c1aad Mon Sep 17 00:00:00 2001 From: zelig Date: Mon, 23 Jun 2014 12:55:38 +0100 Subject: refactor config (transitional). Details: - ReadConfig initialiser sets up global ethutil.Config via config file passed from wrappers - does not write out adhoc default (not meant to) but creates empty config file if it does not exist so that globalconf does not complain if persists a flag - default datadir and default config file set together with other flag defaults in wrappers - default assetpath set together with other command line flags defaults in gui wrapper (not in ethutil.Config or ui/ui_lib) - add EnvPrefix, to handle environment variable options too via globalconf - this is still transitional: global Config should just be a wrapper around globalconfig config handler and should be moved to go-ethereum - actual eth stack config should not be global instead config handled properly with explicit dependency injectioninto eth stack component instances --- ethutil/config.go | 200 ++++++------------------------------------------------ 1 file changed, 20 insertions(+), 180 deletions(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index a573e108b..52537ffa6 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -4,18 +4,14 @@ import ( "flag" "fmt" "github.com/rakyll/globalconf" - "log" - "os" - "os/user" - "path" "runtime" + "os" ) // Config struct type config struct { Db Database - Log *Logger ExecPath string Debug bool Ver string @@ -26,62 +22,31 @@ type config struct { conf *globalconf.GlobalConf } -const defaultConf = ` -id = "" -port = 30303 -upnp = true -maxpeer = 10 -rpc = false -rpcport = 8080 -` - var Config *config -func ApplicationFolder(base string) string { - usr, _ := user.Current() - p := path.Join(usr.HomeDir, base) - - if len(base) > 0 { - //Check if the logging directory already exists, create it if not - _, err := os.Stat(p) - if err != nil { - if os.IsNotExist(err) { - log.Printf("Debug logging directory %s doesn't exist, creating it\n", p) - os.Mkdir(p, 0777) - - } - } - - iniFilePath := path.Join(p, "conf.ini") - _, err = os.Stat(iniFilePath) - if err != nil && os.IsNotExist(err) { - file, err := os.Create(iniFilePath) - if err != nil { - fmt.Println(err) - } else { - assetPath := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "ethereal", "assets") - file.Write([]byte(defaultConf + "\nasset_path = " + assetPath)) - } - } - } - - return p -} - // Read config // -// Initialize the global Config variable with default settings -func ReadConfig(base string, logTypes LoggerType, g *globalconf.GlobalConf, id string) *config { +// Initialize Config from Config File +func ReadConfig(ConfigFile string, Datadir string, Identifier string, EnvPrefix string) *config { if Config == nil { - path := ApplicationFolder(base) - - Config = &config{ExecPath: path, Debug: true, Ver: "0.5.14"} - Config.conf = g - Config.Identifier = id - Config.Log = NewLogger(logTypes, LogLevelDebug) + // create ConfigFile if does not exist, otherwise globalconf panic when trying to persist flags + _, err := os.Stat(ConfigFile) + if err != nil && os.IsNotExist(err) { + fmt.Printf("config file '%s' doesn't exist, creating it\n", ConfigFile) + os.Create(ConfigFile) + } + g, err := globalconf.NewWithOptions(&globalconf.Options{ + Filename: ConfigFile, + EnvPrefix: EnvPrefix, + }) + if err != nil { + fmt.Println(err) + } else { + g.ParseAll() + } + Config = &config{ExecPath: Datadir, Debug: true, Ver: "0.5.14", conf: g, Identifier: Identifier} Config.SetClientString("Ethereum(G)") } - return Config } @@ -98,137 +63,12 @@ func (c *config) SetIdentifier(id string) { c.Set("id", id) } +// provides persistence for flags func (c *config) Set(key, value string) { f := &flag.Flag{Name: key, Value: &confValue{value}} c.conf.Set("", f) } -type LoggerType byte - -const ( - LogFile = 0x1 - LogStd = 0x2 -) - -type LogSystem interface { - Println(v ...interface{}) - Printf(format string, v ...interface{}) -} - -type Logger struct { - logSys []LogSystem - logLevel int -} - -func NewLogger(flag LoggerType, level int) *Logger { - var loggers []LogSystem - - 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) - if err != nil { - log.Panic("unable to create file logger", err) - } - - log := log.New(file, "", flags) - - loggers = append(loggers, log) - } - if flag&LogStd > 0 { - log := log.New(os.Stdout, "", flags) - loggers = append(loggers, log) - } - - return &Logger{logSys: loggers, logLevel: level} -} - -func (self *Logger) SetLevel(level int) { - self.logLevel = level -} - -func (log *Logger) AddLogSystem(logger LogSystem) { - log.logSys = append(log.logSys, logger) -} - -const ( - LogLevelSystem = iota - LogLevelDebug - LogLevelInfo -) - -func (log *Logger) Debugln(v ...interface{}) { - if log.logLevel != LogLevelDebug { - return - } - - for _, logger := range log.logSys { - logger.Println(v...) - } -} - -func (log *Logger) Debugf(format string, v ...interface{}) { - 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 - } - - for _, logger := range log.logSys { - logger.Printf(format, v...) - } -} - -func (log *Logger) Fatal(v ...interface{}) { - if log.logLevel > LogLevelInfo { - return - } - - for _, logger := range log.logSys { - logger.Println(v...) - } - - os.Exit(1) -} - -func (log *Logger) Println(level int, v ...interface{}) { - if log.logLevel > level { - return - } - - for _, logger := range log.logSys { - logger.Println(v...) - } -} - -func (log *Logger) Printf(level int, format string, v ...interface{}) { - if log.logLevel > level { - return - } - - for _, logger := range log.logSys { - logger.Printf(format, v...) - } -} - type confValue struct { value string } -- cgit v1.2.3 From 853053a3b204ddf4ae935e70e0aa5b5d8994493e Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 26 Jun 2014 18:45:57 +0100 Subject: go fmt --- ethutil/config.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 52537ffa6..aa4ae9c3e 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -4,8 +4,8 @@ import ( "flag" "fmt" "github.com/rakyll/globalconf" - "runtime" "os" + "runtime" ) // Config struct @@ -29,21 +29,21 @@ var Config *config // Initialize Config from Config File func ReadConfig(ConfigFile string, Datadir string, Identifier string, EnvPrefix string) *config { if Config == nil { - // create ConfigFile if does not exist, otherwise globalconf panic when trying to persist flags - _, err := os.Stat(ConfigFile) - if err != nil && os.IsNotExist(err) { + // create ConfigFile if does not exist, otherwise globalconf panic when trying to persist flags + _, err := os.Stat(ConfigFile) + if err != nil && os.IsNotExist(err) { fmt.Printf("config file '%s' doesn't exist, creating it\n", ConfigFile) - os.Create(ConfigFile) - } - g, err := globalconf.NewWithOptions(&globalconf.Options{ - Filename: ConfigFile, - EnvPrefix: EnvPrefix, + os.Create(ConfigFile) + } + g, err := globalconf.NewWithOptions(&globalconf.Options{ + Filename: ConfigFile, + EnvPrefix: EnvPrefix, }) if err != nil { - fmt.Println(err) - } else { - g.ParseAll() - } + fmt.Println(err) + } else { + g.ParseAll() + } Config = &config{ExecPath: Datadir, Debug: true, Ver: "0.5.14", conf: g, Identifier: Identifier} Config.SetClientString("Ethereum(G)") } -- cgit v1.2.3 From d551a75c35027a3cf6344293923cdcdab61d5f38 Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 26 Jun 2014 21:20:02 +0100 Subject: bump v5.15 --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index aa4ae9c3e..b253aa203 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -44,7 +44,7 @@ func ReadConfig(ConfigFile string, Datadir string, Identifier string, EnvPrefix } else { g.ParseAll() } - Config = &config{ExecPath: Datadir, Debug: true, Ver: "0.5.14", conf: g, Identifier: Identifier} + Config = &config{ExecPath: Datadir, Debug: true, Ver: "0.5.15", conf: g, Identifier: Identifier} Config.SetClientString("Ethereum(G)") } return Config -- cgit v1.2.3 From 79009ca074d77561c655b65254103b4070b74c69 Mon Sep 17 00:00:00 2001 From: zelig Date: Fri, 27 Jun 2014 15:56:45 +0100 Subject: transitional ethutil.ReadConfig fixes in ethchain tests (they still fail! FIXME :) --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index aa4ae9c3e..b253aa203 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -44,7 +44,7 @@ func ReadConfig(ConfigFile string, Datadir string, Identifier string, EnvPrefix } else { g.ParseAll() } - Config = &config{ExecPath: Datadir, Debug: true, Ver: "0.5.14", conf: g, Identifier: Identifier} + Config = &config{ExecPath: Datadir, Debug: true, Ver: "0.5.15", conf: g, Identifier: Identifier} Config.SetClientString("Ethereum(G)") } return Config -- cgit v1.2.3 From d87857ffdb822d0c510bcff385f7ef0328edb2ca Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 29 Jun 2014 15:59:57 +0100 Subject: config Pubkey removed (unused) --- ethutil/config.go | 1 - 1 file changed, 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index b253aa203..8a005670f 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -16,7 +16,6 @@ type config struct { Debug bool Ver string ClientString string - Pubkey []byte Identifier string conf *globalconf.GlobalConf -- cgit v1.2.3 From 39263b674c1a8a13a1c29349a48b3cdc4c5948db Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 1 Jul 2014 09:56:10 +0200 Subject: Paranoia --- ethutil/config.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index b253aa203..6ebb5e8cd 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -14,6 +14,7 @@ type config struct { ExecPath string Debug bool + Paranoia bool Ver string ClientString string Pubkey []byte @@ -44,7 +45,7 @@ func ReadConfig(ConfigFile string, Datadir string, Identifier string, EnvPrefix } else { g.ParseAll() } - Config = &config{ExecPath: Datadir, Debug: true, Ver: "0.5.15", conf: g, Identifier: Identifier} + Config = &config{ExecPath: Datadir, Debug: true, Ver: "0.5.15", conf: g, Identifier: Identifier, Paranoia: true} Config.SetClientString("Ethereum(G)") } return Config -- cgit v1.2.3 From 7a9ff4f8d45e741625bc32fde59b3dfe90851492 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 1 Jul 2014 16:28:17 +0200 Subject: bump --- ethutil/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 675175cdd..d716005b5 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -44,7 +44,7 @@ func ReadConfig(ConfigFile string, Datadir string, Identifier string, EnvPrefix } else { g.ParseAll() } - Config = &config{ExecPath: Datadir, Debug: true, Ver: "0.5.15", conf: g, Identifier: Identifier, Paranoia: true} + Config = &config{ExecPath: Datadir, Debug: true, Ver: "0.5.16", conf: g, Identifier: Identifier, Paranoia: true} Config.SetClientString("Ethereum(G)") } return Config -- cgit v1.2.3 From f02602d02d12204a10c2aa9d1d43332b1be2fe0a Mon Sep 17 00:00:00 2001 From: zelig Date: Thu, 3 Jul 2014 17:30:51 +0100 Subject: ConfigManager (transitional) - remove clientstring handling from ethutil.Config - ReadConfig takes no Identifier argument - members Ver, ClientString, ClientIdentifier removed from Config - type ConfValue removed - expose public type ethutil.ConfigManager - Set -> Save(key string, value interface{}) now takes any value to allow for persisting non-string values directly - TODO: eliminate all eth specific configs, just a wrapper around globalconf --- ethutil/config.go | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index d716005b5..c9b86100b 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -5,29 +5,25 @@ import ( "fmt" "github.com/rakyll/globalconf" "os" - "runtime" ) // Config struct -type config struct { +type ConfigManager struct { Db Database - ExecPath string - Debug bool - Paranoia bool - Ver string - ClientString string - Identifier string + ExecPath string + Debug bool + Paranoia bool conf *globalconf.GlobalConf } -var Config *config +var Config *ConfigManager // Read config // // Initialize Config from Config File -func ReadConfig(ConfigFile string, Datadir string, Identifier string, EnvPrefix string) *config { +func ReadConfig(ConfigFile string, Datadir string, EnvPrefix string) *ConfigManager { if Config == nil { // create ConfigFile if does not exist, otherwise globalconf panic when trying to persist flags _, err := os.Stat(ConfigFile) @@ -44,34 +40,30 @@ func ReadConfig(ConfigFile string, Datadir string, Identifier string, EnvPrefix } else { g.ParseAll() } - Config = &config{ExecPath: Datadir, Debug: true, Ver: "0.5.16", conf: g, Identifier: Identifier, Paranoia: true} - Config.SetClientString("Ethereum(G)") + Config = &ConfigManager{ExecPath: Datadir, Debug: true, conf: g, Paranoia: true} } return Config } -// Set client string -// -func (c *config) SetClientString(str string) { - os := runtime.GOOS - cust := c.Identifier - Config.ClientString = fmt.Sprintf("%s/v%s/%s/%s/Go", str, c.Ver, cust, os) -} - -func (c *config) SetIdentifier(id string) { - c.Identifier = id - c.Set("id", id) -} - // provides persistence for flags -func (c *config) Set(key, value string) { - f := &flag.Flag{Name: key, Value: &confValue{value}} +func (c *ConfigManager) Save(key string, value interface{}) { + f := &flag.Flag{Name: key, Value: newConfValue(value)} c.conf.Set("", f) } +func (c *ConfigManager) Delete(key string) { + c.conf.Delete("", key) +} + +// private type implementing flag.Value type confValue struct { value string } +// generic constructor to allow persising non-string values directly +func newConfValue(value interface{}) *confValue { + return &confValue{fmt.Sprintf("%v", value)} +} + func (self confValue) String() string { return self.value } func (self confValue) Set(s string) error { self.value = s; return nil } -- cgit v1.2.3 From 9010857677ac374e09bab62a89f2fb52c11ed6d3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 11 Jul 2014 16:04:09 +0200 Subject: Special diff output for execution --- ethutil/config.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index c9b86100b..2f3d706fe 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -13,6 +13,7 @@ type ConfigManager struct { ExecPath string Debug bool + Diff bool Paranoia bool conf *globalconf.GlobalConf -- cgit v1.2.3 From 04f8c455e2d8585902e2c9f0cfb8717ef74a65ca Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 14 Jul 2014 00:37:50 +0200 Subject: Added diff type --- ethutil/config.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 2f3d706fe..41bece21d 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -14,6 +14,7 @@ type ConfigManager struct { ExecPath string Debug bool Diff bool + DiffType string Paranoia bool conf *globalconf.GlobalConf -- cgit v1.2.3 From 41bd38147c2e5968283facf641b2444c09f53d14 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 26 Jul 2014 11:24:44 +0200 Subject: Clean up and util methods --- ethutil/config.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 41bece21d..81052318e 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -3,8 +3,9 @@ package ethutil import ( "flag" "fmt" - "github.com/rakyll/globalconf" "os" + + "github.com/rakyll/globalconf" ) // Config struct @@ -28,8 +29,7 @@ var Config *ConfigManager func ReadConfig(ConfigFile string, Datadir string, EnvPrefix string) *ConfigManager { if Config == nil { // create ConfigFile if does not exist, otherwise globalconf panic when trying to persist flags - _, err := os.Stat(ConfigFile) - if err != nil && os.IsNotExist(err) { + if !FileExist(ConfigFile) { fmt.Printf("config file '%s' doesn't exist, creating it\n", ConfigFile) os.Create(ConfigFile) } -- cgit v1.2.3 From c5bd32b0ad1a3d0fd20a3d1014cc8a97d889dc28 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 14 Oct 2014 11:48:52 +0200 Subject: Refactored VM to two separate VMs; std & debug Standard VM should be about 10x faster than the debug VM. Some error checking has been removed, all of the log statements and therefor quite some unnecessary if-statements. --- ethutil/config.go | 1 + 1 file changed, 1 insertion(+) (limited to 'ethutil/config.go') diff --git a/ethutil/config.go b/ethutil/config.go index 81052318e..ccc7714d0 100644 --- a/ethutil/config.go +++ b/ethutil/config.go @@ -17,6 +17,7 @@ type ConfigManager struct { Diff bool DiffType string Paranoia bool + VmType int conf *globalconf.GlobalConf } -- cgit v1.2.3