aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2014-04-16 20:37:04 +0800
committerzelig <viktor.tron@gmail.com>2014-04-16 20:37:04 +0800
commitf4c13f865634bae6c9cc7cd0478b7765a24fa695 (patch)
tree9a8ef8086c50d546971fa320ed46abbaf8f18cee
parent7f0c974008b62115c5c2685dee909b379ca1c6fc (diff)
downloaddexon-f4c13f865634bae6c9cc7cd0478b7765a24fa695.tar.gz
dexon-f4c13f865634bae6c9cc7cd0478b7765a24fa695.tar.zst
dexon-f4c13f865634bae6c9cc7cd0478b7765a24fa695.zip
logfile
- add logfile option to ethereum client flags - fallback to StdOut - Logger appended to ethutil.Config.Log loggers - wrapper uses ethutil.Config.Log
-rw-r--r--ethereum/config.go4
-rw-r--r--ethereum/ethereum.go26
2 files changed, 23 insertions, 7 deletions
diff --git a/ethereum/config.go b/ethereum/config.go
index e4935dfed..899a17ca6 100644
--- a/ethereum/config.go
+++ b/ethereum/config.go
@@ -15,8 +15,7 @@ var GenAddr bool
var UseSeed bool
var ImportKey string
var ExportKey bool
-
-//var UseGui bool
+var LogFile string
var DataDir string
func Init() {
@@ -29,6 +28,7 @@ func Init() {
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
flag.BoolVar(&ExportKey, "export", false, "export private key")
flag.StringVar(&OutboundPort, "p", "30303", "listening port")
+ flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
flag.StringVar(&DataDir, "dir", ".ethereum", "ethereum data directory")
flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)")
flag.IntVar(&MaxPeer, "x", 5, "maximum desired peers")
diff --git a/ethereum/ethereum.go b/ethereum/ethereum.go
index e1e803771..f00c75ad0 100644
--- a/ethereum/ethereum.go
+++ b/ethereum/ethereum.go
@@ -25,7 +25,6 @@ func RegisterInterupts(s *eth.Ethereum) {
go func() {
for sig := range c {
fmt.Printf("Shutting down (%v) ... \n", sig)
-
s.Stop()
}
}()
@@ -36,8 +35,25 @@ func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
- ethchain.InitFees()
+ // set logger
+ var logger *log.Logger
+ flags := log.LstdFlags
+
+ if LogFile != "" {
+ logfile, err := os.OpenFile(LogFile, os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
+ if err != nil {
+ panic(fmt.Sprintf("error opening log file '%s': %v", LogFile, err))
+ }
+ defer logfile.Close()
+ log.SetOutput(logfile)
+ logger = log.New(logfile, "", flags)
+ } else {
+ logger = log.New(os.Stdout, "", flags)
+ }
ethutil.ReadConfig(DataDir)
+ ethutil.Config.Log.AddLogSystem(logger)
+
+ ethchain.InitFees()
ethutil.Config.Seed = UseSeed
// Instantiated a eth stack
@@ -108,7 +124,7 @@ func main() {
os.Exit(0)
}
- log.Printf("Starting Ethereum v%s\n", ethutil.Config.Ver)
+ ethutil.Config.Log.Infoln(fmt.Sprintf("Starting Ethereum v%s", ethutil.Config.Ver))
// Set the max peers
ethereum.MaxPeers = MaxPeer
@@ -128,13 +144,13 @@ func main() {
ethereum.Start()
if StartMining {
- log.Printf("Miner started\n")
+ ethutil.Config.Log.Infoln("Miner started")
// Fake block mining. It broadcasts a new block every 5 seconds
go func() {
if StartMining {
- log.Printf("Miner started\n")
+ ethutil.Config.Log.Infoln("Miner started")
go func() {
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))