refactor: log with zap
This commit is contained in:
@ -2,7 +2,7 @@ package part
|
||||
|
||||
import (
|
||||
"github.com/cyrilix/robocar-protobuf/go/events"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.uber.org/zap"
|
||||
"gocv.io/x/gocv"
|
||||
"image"
|
||||
"image/color"
|
||||
@ -23,11 +23,11 @@ func (rd *RoadDetector) Close() error {
|
||||
var err error
|
||||
err = nil
|
||||
if err1 := rd.thresholdLowerBound.Close(); err1 != nil {
|
||||
log.Errorf("unable to close thresholdLowerBound resource: %v", err1)
|
||||
zap.S().Errorf("unable to close thresholdLowerBound resource: %v", err1)
|
||||
err = err1
|
||||
}
|
||||
if err2 := rd.thresholdUpperBound.Close(); err2 != nil {
|
||||
log.Errorf("unable to close thresholdUpperBound resource: %v", err2)
|
||||
zap.S().Errorf("unable to close thresholdUpperBound resource: %v", err2)
|
||||
err = err2
|
||||
}
|
||||
return err
|
||||
@ -51,7 +51,7 @@ func (rd *RoadDetector) DetectRoadContour(imgGray *gocv.Mat, horizonRow int) *go
|
||||
img := imgGray.Clone()
|
||||
defer func() {
|
||||
if err := img.Close(); err != nil {
|
||||
log.Warnf("unable to close mat resource: %v", err)
|
||||
zap.S().Warnf("unable to close mat resource: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
@ -125,7 +125,7 @@ func (rd *RoadDetector) ComputeEllipsis(road *gocv.PointVector) *events.Ellipse
|
||||
rotatedRect := gocv.FitEllipse(*road)
|
||||
|
||||
trust := rd.computeTrustFromCenter(&rotatedRect.Center)
|
||||
log.Debugf("Trust: %v", trust)
|
||||
zap.S().Debugf("Trust: %v", trust)
|
||||
|
||||
return &events.Ellipse{
|
||||
Center: &events.Point{
|
||||
|
@ -3,7 +3,7 @@ package part
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/cyrilix/robocar-protobuf/go/events"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.uber.org/zap"
|
||||
"gocv.io/x/gocv"
|
||||
"image"
|
||||
"image/color"
|
||||
@ -82,7 +82,7 @@ func TestRoadDetection_DetectRoadContour(t *testing.T) {
|
||||
imgGray := toGray(*c.img)
|
||||
contours := rd.DetectRoadContour(imgGray, c.horizon)
|
||||
|
||||
log.Infof("[%v] contour: %v", c.name, *contours)
|
||||
zap.S().Infof("[%v] contour: %v", c.name, *contours)
|
||||
expected := gocv.NewPointVectorFromPoints(c.expectedContour)
|
||||
|
||||
if contours.Size() != expected.Size() {
|
||||
|
14
part/part.go
14
part/part.go
@ -5,8 +5,9 @@ import (
|
||||
"github.com/cyrilix/robocar-protobuf/go/events"
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/golang/protobuf/proto"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.uber.org/zap"
|
||||
"gocv.io/x/gocv"
|
||||
"log"
|
||||
)
|
||||
|
||||
type RoadPart struct {
|
||||
@ -32,6 +33,7 @@ func NewRoadPart(client mqtt.Client, horizon int, cameraTopic, roadTopic string)
|
||||
}
|
||||
|
||||
func (r *RoadPart) Start() error {
|
||||
log := zap.S()
|
||||
registerCallBacks(r)
|
||||
|
||||
var frame = frameToProcess{}
|
||||
@ -69,7 +71,7 @@ var registerCallBacks = func(r *RoadPart) {
|
||||
func (r *RoadPart) Stop() {
|
||||
defer func() {
|
||||
if err := r.roadDetector.Close(); err != nil {
|
||||
log.Errorf("unable to close roadDetector: %v", err)
|
||||
zap.S().Errorf("unable to close roadDetector: %v", err)
|
||||
}
|
||||
}()
|
||||
close(r.readyForNext)
|
||||
@ -81,13 +83,13 @@ func (r *RoadPart) OnFrame(_ mqtt.Client, msg mqtt.Message) {
|
||||
var frameMsg events.FrameMessage
|
||||
err := proto.Unmarshal(msg.Payload(), &frameMsg)
|
||||
if err != nil {
|
||||
log.Errorf("unable to unmarshal %T message: %v", frameMsg, err)
|
||||
zap.S().Errorf("unable to unmarshal %T message: %v", frameMsg, err)
|
||||
return
|
||||
}
|
||||
|
||||
img, err := gocv.IMDecode(frameMsg.GetFrame(), gocv.IMReadUnchanged)
|
||||
if err != nil {
|
||||
log.Errorf("unable to decode image: %v", err)
|
||||
zap.S().Errorf("unable to decode image: %v", err)
|
||||
return
|
||||
}
|
||||
frame := frameToProcess{
|
||||
@ -107,7 +109,7 @@ func (r *RoadPart) processFrame(frame *frameToProcess) {
|
||||
imgGray := gocv.NewMatWithSize(img.Rows(), img.Cols(), gocv.MatTypeCV8UC1)
|
||||
defer func() {
|
||||
if err := imgGray.Close(); err != nil {
|
||||
log.Warnf("unable to close Mat resource: %v", err)
|
||||
zap.S().Warnf("unable to close Mat resource: %v", err)
|
||||
}
|
||||
}()
|
||||
gocv.CvtColor(img, &imgGray, gocv.ColorRGBToGray)
|
||||
@ -131,7 +133,7 @@ func (r *RoadPart) processFrame(frame *frameToProcess) {
|
||||
|
||||
payload, err := proto.Marshal(&msg)
|
||||
if err != nil {
|
||||
log.Errorf("unable to marshal %T to protobuf: %err", msg, err)
|
||||
zap.S().Errorf("unable to marshal %T to protobuf: %err", msg, err)
|
||||
return
|
||||
}
|
||||
publish(r.client, r.roadTopic, &payload)
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.uber.org/zap"
|
||||
"io/ioutil"
|
||||
"sync"
|
||||
"testing"
|
||||
@ -91,7 +91,7 @@ func frameRefFromPayload(payload []byte) *events.FrameRef {
|
||||
var msg events.FrameMessage
|
||||
err := proto.Unmarshal(payload, &msg)
|
||||
if err != nil {
|
||||
log.Errorf("unable to unmarchal %T msg: %v", msg, err)
|
||||
zap.S().Errorf("unable to unmarshal %T msg: %v", msg, err)
|
||||
}
|
||||
return msg.GetId()
|
||||
}
|
||||
|
Reference in New Issue
Block a user