diff options
author | IWASE Yusuke <iwase.yusuke0@gmail.com> | 2018-05-16 10:44:42 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-05-23 13:00:33 +0900 |
commit | cb259ecb0f4135694e86c0605a226779ebd6b8f0 (patch) | |
tree | a259e07b966d23b193d4ac918456512efc5a45bb /zebra/zapi.go | |
parent | 9d184af6c62a08cdadd7f939d11a578547a7a7ee (diff) |
zebra: Improve logs for received messages from Zebra
Currently, the received messages from Zebra are printed as byte slice
and it is difficult to determine which message was received.
This patch fixes to output the received message as the decoded
structure for the readability.
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'zebra/zapi.go')
-rw-r--r-- | zebra/zapi.go | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/zebra/zapi.go b/zebra/zapi.go index 942e8699..8b71f483 100644 --- a/zebra/zapi.go +++ b/zebra/zapi.go @@ -571,43 +571,51 @@ func NewClient(network, address string, typ ROUTE_TYPE, version uint8) (*Client, receiveSingleMsg := func() (*Message, error) { headerBuf, err := readAll(conn, int(HeaderSize(version))) if err != nil { - err = fmt.Errorf("failed to read header: %s", err) log.WithFields(log.Fields{ "Topic": "Zebra", - }).Error(err) + "Error": err, + }).Error("failed to read header") return nil, err } - log.WithFields(log.Fields{ - "Topic": "Zebra", - }).Debugf("read header from zebra: %v", headerBuf) + hd := &Header{} err = hd.DecodeFromBytes(headerBuf) if err != nil { - err = fmt.Errorf("failed to decode header: %s", err) log.WithFields(log.Fields{ "Topic": "Zebra", - }).Error(err) + "Data": headerBuf, + "Error": err, + }).Error("failed to decode header") return nil, err } bodyBuf, err := readAll(conn, int(hd.Len-HeaderSize(version))) if err != nil { - err = fmt.Errorf("failed to read body: %s", err) log.WithFields(log.Fields{ - "Topic": "Zebra", - }).Error(err) + "Topic": "Zebra", + "Header": hd, + "Error": err, + }).Error("failed to read body") return nil, err } - log.WithFields(log.Fields{ - "Topic": "Zebra", - }).Debugf("read body from zebra: %v", bodyBuf) + m, err := ParseMessage(hd, bodyBuf) if err != nil { + // Just outputting warnings (not error message) and ignore this + // error considering the case that body parser is not implemented + // yet. log.WithFields(log.Fields{ - "Topic": "Zebra", - }).Warnf("failed to parse message: %s", err) + "Topic": "Zebra", + "Header": hd, + "Data": bodyBuf, + "Error": err, + }).Warn("failed to decode body") return nil, nil } + log.WithFields(log.Fields{ + "Topic": "Zebra", + "Message": m, + }).Debug("read message from zebra") return m, nil } |