forked from cerc-io/plugeth
Logging mechanism
This commit is contained in:
parent
63883bf27d
commit
6d52da58d9
@ -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
|
||||
}
|
||||
|
5
peer.go
5
peer.go
@ -244,6 +244,8 @@ func (p *Peer) writeMessage(msg *ethwire.Msg) {
|
||||
}
|
||||
}
|
||||
|
||||
ethutil.Config.Log.Println(ethutil.LogLevelSystem, "<=", msg.Type, msg.Data)
|
||||
|
||||
err := ethwire.WriteMessage(p.conn, msg)
|
||||
if err != nil {
|
||||
ethutil.Config.Log.Debugln("[PEER] Can't send message:", err)
|
||||
@ -264,6 +266,7 @@ out:
|
||||
select {
|
||||
// Main message queue. All outbound messages are processed through here
|
||||
case msg := <-p.outputQueue:
|
||||
|
||||
p.writeMessage(msg)
|
||||
p.lastSend = time.Now()
|
||||
|
||||
@ -316,6 +319,8 @@ func (p *Peer) HandleInbound() {
|
||||
ethutil.Config.Log.Debugln(err)
|
||||
}
|
||||
for _, msg := range msgs {
|
||||
ethutil.Config.Log.Println(ethutil.LogLevelSystem, "=>", msg.Type, msg.Data)
|
||||
|
||||
switch msg.Type {
|
||||
case ethwire.MsgHandshakeTy:
|
||||
// Version message
|
||||
|
Loading…
Reference in New Issue
Block a user