diff options
-rw-r--r-- | ethereal/ui/gui.go | 57 | ||||
-rw-r--r-- | ethereal/ui/html_container.go | 4 | ||||
-rw-r--r-- | ethereal/ui/ui_lib.go | 4 | ||||
-rw-r--r-- | ethereum/javascript_runtime.go | 8 | ||||
-rw-r--r-- | ethereum/repl.go | 2 |
5 files changed, 46 insertions, 29 deletions
diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 1037ba5ac..ed29e2485 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/eth-go/ethdb" "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/go-ethereum/utils" "github.com/go-qml/qml" "math/big" @@ -15,6 +16,8 @@ import ( "time" ) +var logger = ethlog.NewLogger("GUI") + type Gui struct { // The main application window win *qml.Window @@ -33,10 +36,11 @@ type Gui struct { addr []byte pub *ethpub.PEthereum + logLevel ethlog.LogLevel } // Create GUI, but doesn't start it -func New(ethereum *eth.Ethereum) *Gui { +func New(ethereum *eth.Ethereum, logLevel ethlog.LogLevel) *Gui { lib := &EthLib{stateManager: ethereum.StateManager(), blockChain: ethereum.BlockChain(), txPool: ethereum.TxPool()} db, err := ethdb.NewLDBDatabase("tx_database") if err != nil { @@ -52,7 +56,7 @@ func New(ethereum *eth.Ethereum) *Gui { pub := ethpub.NewPEthereum(ethereum) - return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub} + return &Gui{eth: ethereum, lib: lib, txDb: db, addr: addr, pub: pub, logLevel: logLevel} } func (gui *Gui) Start(assetPath string) { @@ -90,16 +94,15 @@ func (gui *Gui) Start(assetPath string) { win, err = gui.showKeyImport(context) } else { win, err = gui.showWallet(context) - - ethutil.Config.Log.AddLogSystem(gui) + ethlog.AddLogSystem(gui) } if err != nil { - ethutil.Config.Log.Infoln("FATAL: asset not found: you can set an alternative asset path on on the command line using option 'asset_path'", err) + logger.Errorln("asset not found: you can set an alternative asset path on the command line using option 'asset_path'", err) panic(err) } - ethutil.Config.Log.Infoln("[GUI] Starting GUI") + logger.Infoln("Starting GUI") win.Show() win.Wait() @@ -315,22 +318,6 @@ func (gui *Gui) setPeerInfo() { } } -// Logging functions that log directly to the GUI interface -func (gui *Gui) Println(v ...interface{}) { - str := strings.TrimRight(fmt.Sprintln(v...), "\n") - lines := strings.Split(str, "\n") - for _, line := range lines { - gui.win.Root().Call("addLog", line) - } -} - -func (gui *Gui) Printf(format string, v ...interface{}) { - str := strings.TrimRight(fmt.Sprintf(format, v...), "\n") - lines := strings.Split(str, "\n") - for _, line := range lines { - gui.win.Root().Call("addLog", line) - } -} func (gui *Gui) RegisterName(name string) { keyPair := ethutil.GetKeyRing().Get(0) name = fmt.Sprintf("\"%s\"\n1", name) @@ -357,6 +344,28 @@ func (gui *Gui) ClientId() string { return ethutil.Config.Identifier } -func (gui *Gui) SetLogLevel(level int) { - ethutil.Config.Log.SetLevel(level) +// functions that allow Gui to implement interface ethlog.LogSystem +func (gui *Gui) SetLogLevel(level ethlog.LogLevel) { + gui.logLevel = level +} + +func (gui *Gui) GetLogLevel() ethlog.LogLevel { + return gui.logLevel +} + +func (gui *Gui) Println(v ...interface{}) { + gui.printLog(fmt.Sprintln(v...)) +} + +func (gui *Gui) Printf(format string, v ...interface{}) { + gui.printLog(fmt.Sprintf(format, v...)) +} + +// Print function that logs directly to the GUI +func (gui *Gui) printLog(s string) { + str := strings.TrimRight(s, "\n") + lines := strings.Split(str, "\n") + for _, line := range lines { + gui.win.Root().Call("addLog", line) + } } diff --git a/ethereal/ui/html_container.go b/ethereal/ui/html_container.go index 3867c0353..d7dc80af7 100644 --- a/ethereal/ui/html_container.go +++ b/ethereal/ui/html_container.go @@ -96,11 +96,11 @@ func (app *HtmlApplication) NewWatcher(quitChan chan bool) { app.watcher.Close() break out case <-app.watcher.Event: - //ethutil.Config.Log.Debugln("Got event:", ev) + //logger.Debugln("Got event:", ev) app.webView.Call("reload") case err := <-app.watcher.Error: // TODO: Do something here - ethutil.Config.Log.Infoln("Watcher error:", err) + logger.Infoln("Watcher error:", err) } } }() diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 791d4fe09..2dd66f4fd 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -39,7 +39,7 @@ func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { func (ui *UiLib) Open(path string) { component, err := ui.engine.LoadFile(path[7:]) if err != nil { - ethutil.Config.Log.Debugln(err) + logger.Debugln(err) } win := component.CreateWindow(nil) @@ -59,7 +59,7 @@ func (ui *UiLib) OpenHtml(path string) { func (ui *UiLib) Muted(content string) { component, err := ui.engine.LoadFile(ui.AssetPath("qml/muted.qml")) if err != nil { - ethutil.Config.Log.Debugln(err) + logger.Debugln(err) return } diff --git a/ethereum/javascript_runtime.go b/ethereum/javascript_runtime.go index b05d39232..34b805e7f 100644 --- a/ethereum/javascript_runtime.go +++ b/ethereum/javascript_runtime.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/go-ethereum/utils" "github.com/obscuren/otto" "io/ioutil" @@ -14,6 +15,8 @@ import ( "path/filepath" ) +var jsrelogger = ethlog.NewLogger("JSRE") + type JSRE struct { ethereum *eth.Ethereum vm *otto.Otto @@ -31,7 +34,7 @@ func (jsre *JSRE) LoadExtFile(path string) { if err == nil { jsre.vm.Run(result) } else { - ethutil.Config.Log.Debugln("Could not load file:", path) + jsrelogger.Debugln("Could not load file:", path) } } @@ -65,6 +68,8 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE { re.initStdFuncs() + jsrelogger.Infoln("started") + return re } @@ -99,6 +104,7 @@ func (self *JSRE) Stop() { close(self.blockChan) close(self.quitChan) close(self.changeChan) + jsrelogger.Infoln("stopped") } func (self *JSRE) mainLoop() { diff --git a/ethereum/repl.go b/ethereum/repl.go index 0208459ad..a95d73300 100644 --- a/ethereum/repl.go +++ b/ethereum/repl.go @@ -23,11 +23,13 @@ func NewJSRepl(ethereum *eth.Ethereum) *JSRepl { } func (self *JSRepl) Start() { + logger.Infoln("init JS Console") self.read() } func (self *JSRepl) Stop() { self.re.Stop() + logger.Infoln("exit JS Console") } func (self *JSRepl) parseInput(code string) { |