fix: log configuration

This commit is contained in:
Cyrille Nofficial 2021-10-12 17:34:47 +02:00
parent 61d8bd22c4
commit 0001c3e36e
2 changed files with 34 additions and 10 deletions

View File

@ -18,12 +18,8 @@ func main() {
var cameraTopic, steeringTopic string var cameraTopic, steeringTopic string
var modelPath string var modelPath string
var edgeVerbosity int var edgeVerbosity int
var debug bool
lgr, err := zap.NewProductionConfig().Build()
if err != nil {
log.Fatalf("unable to init logger: %v", err)
}
zap.ReplaceGlobals(lgr)
mqttQos := cli.InitIntFlag("MQTT_QOS", 0) mqttQos := cli.InitIntFlag("MQTT_QOS", 0)
_, mqttRetain := os.LookupEnv("MQTT_RETAIN") _, mqttRetain := os.LookupEnv("MQTT_RETAIN")
@ -34,6 +30,7 @@ func main() {
flag.StringVar(&steeringTopic, "mqtt-topic-road", os.Getenv("MQTT_TOPIC_STEERING"), "Mqtt topic to publish road detection result, use MQTT_TOPIC_STEERING if args not set") flag.StringVar(&steeringTopic, "mqtt-topic-road", os.Getenv("MQTT_TOPIC_STEERING"), "Mqtt topic to publish road detection result, use MQTT_TOPIC_STEERING if args not set")
flag.StringVar(&cameraTopic, "mqtt-topic-camera", os.Getenv("MQTT_TOPIC_CAMERA"), "Mqtt topic that contains camera frame values, use MQTT_TOPIC_CAMERA if args not set") flag.StringVar(&cameraTopic, "mqtt-topic-camera", os.Getenv("MQTT_TOPIC_CAMERA"), "Mqtt topic that contains camera frame values, use MQTT_TOPIC_CAMERA if args not set")
flag.IntVar(&edgeVerbosity, "edge-verbosity", 0, "Edge TPU Verbosity") flag.IntVar(&edgeVerbosity, "edge-verbosity", 0, "Edge TPU Verbosity")
flag.BoolVar(&debug, "debug", false, "Display debug logs")
flag.Parse() flag.Parse()
if len(os.Args) <= 1 { if len(os.Args) <= 1 {
@ -41,6 +38,23 @@ func main() {
os.Exit(1) os.Exit(1)
} }
config := zap.NewDevelopmentConfig()
if debug {
config.Level = zap.NewAtomicLevelAt(zap.DebugLevel)
} else {
config.Level = zap.NewAtomicLevelAt(zap.InfoLevel)
}
lgr, err := config.Build()
if err != nil {
log.Fatalf("unable to init logger: %v", err)
}
defer func() {
if err := lgr.Sync(); err != nil {
log.Printf("unable to Sync logger: %v\n", err)
}
}()
zap.ReplaceGlobals(lgr)
if modelPath == "" { if modelPath == "" {
zap.L().Error("model path is mandatory") zap.L().Error("model path is mandatory")
flag.PrintDefaults() flag.PrintDefaults()

View File

@ -61,17 +61,22 @@ func (p *Part) Start() error {
if err != nil { if err != nil {
return fmt.Errorf("cannot get EdgeTPU version: %w", err) return fmt.Errorf("cannot get EdgeTPU version: %w", err)
} }
zap.S().Infof("EdgeTPU Version: %s\n", edgetpuVersion) zap.S().Infof("EdgeTPU Version: %s", edgetpuVersion)
edgetpu.Verbosity(p.edgeVebosity) edgetpu.Verbosity(p.edgeVebosity)
p.options = tflite.NewInterpreterOptions() p.options = tflite.NewInterpreterOptions()
p.options.SetNumThread(4) p.options.SetNumThread(4)
p.options.SetErrorReporter(func(msg string, userData interface{}) { p.options.SetErrorReporter(func(msg string, userData interface{}) {
zap.L().Error(msg, zap.S().Errorw(msg,
zap.Any("userData", userData), "userData", userData,
) )
}, nil) }, nil)
zap.S().Infof("find %d edgetpu devices", len(devices))
zap.S().Infow("configure edgetpu",
"path", devices[0].Path,
"type", uint32(devices[0].Type),
)
// Add the first EdgeTPU device // Add the first EdgeTPU device
d := edgetpu.New(devices[0]) d := edgetpu.New(devices[0])
if d == nil { if d == nil {
@ -85,7 +90,7 @@ func (p *Part) Start() error {
} }
if err := registerCallbacks(p); err != nil { if err := registerCallbacks(p); err != nil {
zap.S().Errorf("unable to register callbacks: %v", err) zap.S().Errorw("unable to register callbacks", "error", err)
return err return err
} }
@ -119,7 +124,8 @@ func (p *Part) onFrame(_ mqtt.Client, message mqtt.Message) {
img, _, err := image.Decode(bytes.NewReader(msg.GetFrame())) img, _, err := image.Decode(bytes.NewReader(msg.GetFrame()))
if err != nil { if err != nil {
zap.L().Error("unable to decode frame", zap.Error(err)) zap.L().Error("unable to decode frame, skip frame", zap.Error(err))
return
} }
steering, confidence, err := p.Value(img) steering, confidence, err := p.Value(img)
@ -130,6 +136,10 @@ func (p *Part) onFrame(_ mqtt.Client, message mqtt.Message) {
) )
return return
} }
zap.L().Debug("new steering value",
zap.Float32("steering", steering),
zap.Float32("confidence", confidence),
)
msgSteering := &events.SteeringMessage{ msgSteering := &events.SteeringMessage{
Steering: steering, Steering: steering,
Confidence: confidence, Confidence: confidence,