diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-21 21:52:42 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-21 21:52:42 +0800 |
commit | a7ad9c309bf72a9f2b4f12001034e1842ca55319 (patch) | |
tree | fa573f69742e3e7cf9b2a8d124a27c9d4c8d3c2b | |
parent | ce862ee7589a0780cebc8a7bb1cf6a75193d55a0 (diff) | |
parent | 38c7c589e4a1b08baaab5b81de6aca7fa853d284 (diff) | |
download | go-tangerine-a7ad9c309bf72a9f2b4f12001034e1842ca55319.tar.gz go-tangerine-a7ad9c309bf72a9f2b4f12001034e1842ca55319.tar.zst go-tangerine-a7ad9c309bf72a9f2b4f12001034e1842ca55319.zip |
Merge branch 'develop' into conversion
-rw-r--r-- | cmd/ethereum/main.go | 4 | ||||
-rw-r--r-- | logger/log.go | 2 | ||||
-rw-r--r-- | logger/logsystem.go | 24 | ||||
-rw-r--r-- | logger/sys.go | 3 | ||||
-rw-r--r-- | p2p/discover/node.go | 4 | ||||
-rw-r--r-- | p2p/message.go | 2 |
6 files changed, 32 insertions, 7 deletions
diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index afaf06948..7d5854230 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -251,7 +251,7 @@ func accountList(ctx *cli.Context) { utils.Fatalf("Could not list accounts: %v", err) } for _, acct := range accts { - fmt.Printf("Address: %#x\n", acct) + fmt.Printf("Address: %x\n", acct) } } @@ -278,7 +278,7 @@ func accountCreate(ctx *cli.Context) { if err != nil { utils.Fatalf("Could not create the account: %v", err) } - fmt.Printf("Address: %#x\n", acct.Address) + fmt.Printf("Address: %x\n", acct.Address) } func importchain(ctx *cli.Context) { diff --git a/logger/log.go b/logger/log.go index 2dbec86de..fab004d0a 100644 --- a/logger/log.go +++ b/logger/log.go @@ -30,6 +30,8 @@ func New(datadir string, logFile string, logLevel int, logFormat string) LogSyst switch logFormat { case "raw": sys = NewRawLogSystem(writer, 0, LogLevel(logLevel)) + case "json": + sys = NewJsonLogSystem(writer, 0, LogLevel(logLevel)) default: sys = NewStdLogSystem(writer, log.LstdFlags, LogLevel(logLevel)) } diff --git a/logger/logsystem.go b/logger/logsystem.go index 8458b938f..1318a9f96 100644 --- a/logger/logsystem.go +++ b/logger/logsystem.go @@ -61,3 +61,27 @@ func (t *rawLogSystem) SetLogLevel(i LogLevel) { func (t *rawLogSystem) GetLogLevel() LogLevel { return LogLevel(atomic.LoadUint32(&t.level)) } + +// NewRawLogSystem creates a LogSystem that prints to the given writer without +// adding extra information. Suitable for preformatted output +func NewJsonLogSystem(writer io.Writer, flags int, level LogLevel) LogSystem { + logger := log.New(writer, "", 0) + return &jsonLogSystem{logger, uint32(level)} +} + +type jsonLogSystem struct { + logger *log.Logger + level uint32 +} + +func (t *jsonLogSystem) LogPrint(level LogLevel, msg string) { + t.logger.Print(msg) +} + +func (t *jsonLogSystem) SetLogLevel(i LogLevel) { + atomic.StoreUint32(&t.level, uint32(i)) +} + +func (t *jsonLogSystem) GetLogLevel() LogLevel { + return LogLevel(atomic.LoadUint32(&t.level)) +} diff --git a/logger/sys.go b/logger/sys.go index bd826b587..db4251a52 100644 --- a/logger/sys.go +++ b/logger/sys.go @@ -76,8 +76,7 @@ func dispatchLoop() { func sysLoop(sys LogSystem, in <-chan message, wg *sync.WaitGroup) { for msg := range in { switch sys.(type) { - case *rawLogSystem: - // This is a semantic hack since rawLogSystem has little to do with JsonLevel + case *jsonLogSystem: if msg.level == JsonLevel { sys.LogPrint(msg.level, msg.msg) } diff --git a/p2p/discover/node.go b/p2p/discover/node.go index de2588258..e1130e0b5 100644 --- a/p2p/discover/node.go +++ b/p2p/discover/node.go @@ -143,12 +143,12 @@ type NodeID [nodeIDBits / 8]byte // NodeID prints as a long hexadecimal number. func (n NodeID) String() string { - return fmt.Sprintf("%#x", n[:]) + return fmt.Sprintf("%x", n[:]) } // The Go syntax representation of a NodeID is a call to HexID. func (n NodeID) GoString() string { - return fmt.Sprintf("discover.HexID(\"%#x\")", n[:]) + return fmt.Sprintf("discover.HexID(\"%x\")", n[:]) } // HexID converts a hex string to a NodeID. diff --git a/p2p/message.go b/p2p/message.go index ef3630a90..b42acbe3c 100644 --- a/p2p/message.go +++ b/p2p/message.go @@ -33,7 +33,7 @@ type Msg struct { // For the decoding rules, please see package rlp. func (msg Msg) Decode(val interface{}) error { if err := rlp.Decode(msg.Payload, val); err != nil { - return newPeerError(errInvalidMsg, "(code %#x) (size %d) %v", msg.Code, msg.Size, err) + return newPeerError(errInvalidMsg, "(code %x) (size %d) %v", msg.Code, msg.Size, err) } return nil } |