mirror of https://github.com/status-im/op-geth.git
Add JsonLogger type
This commit is contained in:
parent
ed7d7b405e
commit
1077109e11
|
@ -44,6 +44,7 @@ type Config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
var logger = ethlogger.NewLogger("SERV")
|
var logger = ethlogger.NewLogger("SERV")
|
||||||
|
var jsonlogger = ethlogger.NewJsonLogger()
|
||||||
|
|
||||||
type Ethereum struct {
|
type Ethereum struct {
|
||||||
// Channel for shutting down the ethereum
|
// Channel for shutting down the ethereum
|
||||||
|
@ -221,6 +222,14 @@ func (s *Ethereum) MaxPeers() int {
|
||||||
|
|
||||||
// Start the ethereum
|
// Start the ethereum
|
||||||
func (s *Ethereum) Start(seed bool) error {
|
func (s *Ethereum) Start(seed bool) error {
|
||||||
|
evd := map[string]interface{}{
|
||||||
|
"version_string": s.ClientIdentity().String(),
|
||||||
|
"guid": ethutil.Bytes2Hex(s.ClientIdentity().Pubkey()),
|
||||||
|
"level": "debug",
|
||||||
|
"coinbase": ethutil.Bytes2Hex(s.KeyManager().Address()),
|
||||||
|
"eth_version": ProtocolVersion,
|
||||||
|
}
|
||||||
|
jsonlogger.Log("starting", evd)
|
||||||
err := s.net.Start()
|
err := s.net.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -13,8 +13,10 @@ logging of mutable state.
|
||||||
package logger
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LogLevel uint32
|
type LogLevel uint32
|
||||||
|
@ -112,3 +114,27 @@ func (logger *Logger) Fatalf(format string, v ...interface{}) {
|
||||||
Flush()
|
Flush()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type JsonLogger struct{}
|
||||||
|
|
||||||
|
func NewJsonLogger() *JsonLogger {
|
||||||
|
return &JsonLogger{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (logger *JsonLogger) Log(msgname string, dict map[string]interface{}) {
|
||||||
|
if _, ok := dict["ts"]; !ok {
|
||||||
|
dict["ts"] = time.Now().Local().Format(time.RFC3339Nano)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIX
|
||||||
|
if _, ok := dict["level"]; !ok {
|
||||||
|
dict["level"] = "debug"
|
||||||
|
}
|
||||||
|
|
||||||
|
obj := map[string]interface{}{
|
||||||
|
msgname: dict,
|
||||||
|
}
|
||||||
|
|
||||||
|
jsontxt, _ := json.Marshal(obj)
|
||||||
|
logMessageC <- message{JsonLevel, fmt.Sprintf("%s", jsontxt)}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue