Refactor logs
This commit is contained in:
@ -24,40 +24,42 @@ const (
|
||||
|
||||
func main() {
|
||||
var mqttBroker, username, password, clientId, topicThrottle, topicSteering string
|
||||
var debug bool
|
||||
|
||||
mqttQos := cli.InitIntFlag("MQTT_QOS", 0)
|
||||
_, mqttRetain := os.LookupEnv("MQTT_RETAIN")
|
||||
|
||||
cli.InitMqttFlags(DefaultClientId, &mqttBroker, &username, &password, &clientId, &mqttQos, &mqttRetain)
|
||||
flag.BoolVar(&debug, "debug", false, "Display raw value to debug")
|
||||
|
||||
var throttleChannel, throttleStoppedPWM, throttleMinPWM, throttleMaxPWM int
|
||||
if err := cli.SetIntDefaultValueFromEnv(&throttleChannel, "THROTTLE_CHANNEL", ThrottleChannel); err != nil {
|
||||
log.Infof("unable to init throttleChannel arg: %v", err)
|
||||
log.Warningf("unable to init throttleChannel arg: %v", err)
|
||||
}
|
||||
if err := cli.SetIntDefaultValueFromEnv(&throttleStoppedPWM, "THROTTLE_STOPPED_PWM", ThrottleStoppedPWM); err != nil {
|
||||
log.Infof("unable to init throttleStoppedPWM arg: %v", err)
|
||||
log.Warningf("unable to init throttleStoppedPWM arg: %v", err)
|
||||
}
|
||||
if err := cli.SetIntDefaultValueFromEnv(&throttleMinPWM, "THROTTLE_MIN_PWM", ThrottleMinPWM); err != nil {
|
||||
log.Infof("unable to init throttleMinPWM arg: %v", err)
|
||||
log.Warningf("unable to init throttleMinPWM arg: %v", err)
|
||||
}
|
||||
if err := cli.SetIntDefaultValueFromEnv(&throttleMaxPWM, "THROTTLE_MAX_PWM", ThrottleMaxPWM); err != nil {
|
||||
log.Infof("unable to init throttleMaxPWM arg: %v", err)
|
||||
log.Warningf("unable to init throttleMaxPWM arg: %v", err)
|
||||
}
|
||||
|
||||
var steeringChannel, steeringLeftPWM, steeringRightPWM int
|
||||
if err := cli.SetIntDefaultValueFromEnv(&steeringChannel, "STEERING_CHANNEL", SteeringChannel); err != nil {
|
||||
log.Infof("unable to init steeringChannel arg: %v", err)
|
||||
log.Warningf("unable to init steeringChannel arg: %v", err)
|
||||
}
|
||||
if err := cli.SetIntDefaultValueFromEnv(&steeringLeftPWM, "STEERING_LEFT_PWM", SteeringLeftPWM); err != nil {
|
||||
log.Infof("unable to init steeringLeftPWM arg: %v", err)
|
||||
log.Warningf("unable to init steeringLeftPWM arg: %v", err)
|
||||
}
|
||||
if err := cli.SetIntDefaultValueFromEnv(&steeringRightPWM, "STEERING_RIGHT_PWM", SteeringRightPWM); err != nil {
|
||||
log.Infof("unable to init steeringRightPWM arg: %v", err)
|
||||
log.Warningf("unable to init steeringRightPWM arg: %v", err)
|
||||
}
|
||||
|
||||
var updatePWMFrequency int
|
||||
if err := cli.SetIntDefaultValueFromEnv(&updatePWMFrequency, "UPDATE_PWM_FREQUENCY", 25); err != nil {
|
||||
log.Infof("unable to init updatePWMFrequency arg: %v", err)
|
||||
log.Warningf("unable to init updatePWMFrequency arg: %v", err)
|
||||
}
|
||||
|
||||
flag.StringVar(&topicThrottle, "mqtt-topic-throttle", os.Getenv("MQTT_TOPIC_THROTTLE"), "Mqtt topic that contains throttle value, use MQTT_TOPIC_THROTTLE if args not set")
|
||||
@ -77,6 +79,10 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if debug {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
|
||||
client, err := cli.Connect(mqttBroker, username, password, clientId)
|
||||
if err != nil {
|
||||
log.Fatalf("unable to connect to mqtt bus: %v", err)
|
||||
|
Reference in New Issue
Block a user