add more logging

This commit is contained in:
Joel Schmid 2021-04-02 22:46:24 +02:00
parent 791518f3be
commit ff28e70c31
4 changed files with 10 additions and 0 deletions

View file

@ -16,6 +16,8 @@ var weatherSource weathersource.WeatherSource
var weatherAPI api.WeatherAPI
func main() {
log.SetOutput(os.Stdout)
//setup new sensorRegistry -> MongodbSensorRegistry
var err error
if sensorRegistry, err = storage.NewMongodbSensorRegistry(config.MongoConfiguration); err != nil {
@ -44,6 +46,7 @@ func main() {
defer weatherAPI.Close()
weatherAPI.AddNewWeatherDataCallback(handleNewWeatherData)
log.Print("Application is running")
err = weatherAPI.Start()
if err != nil {
log.Fatal(err)
@ -54,6 +57,7 @@ func main() {
func handleNewWeatherData(wd storage.WeatherData) error {
_, err := sensorRegistry.ResolveSensorById(wd.SensorId)
if !config.AllowUnregisteredSensors && err != nil {
log.Print("discarded invalid weatherdata")
return fmt.Errorf("could not resolve sensor")
}
weatherStorage.Save(wd)

View file

@ -3,6 +3,7 @@ package storage
import (
"context"
"fmt"
"log"
"time"
"weather-data/config"
@ -23,6 +24,7 @@ func NewInfluxStorage(cfg config.InfluxConfig) (*influxStorage, error) {
influx.config = cfg
influx.client = influxdb2.NewClient(cfg.Host, cfg.Token)
influx.measurement = "data"
log.Print("Successfully created influx-client")
return influx, nil
}
@ -44,6 +46,7 @@ func (storage *influxStorage) Save(data WeatherData) error {
writeAPI := storage.client.WriteAPI(storage.config.Organization, storage.config.Bucket)
writeAPI.WritePoint(datapoint)
log.Print("Written weather data point to influx-db")
return nil
}

View file

@ -48,6 +48,8 @@ func NewMongodbSensorRegistry(mongoCfg config.MongoConfig) (*mongodbSensorRegist
weathersensorsDB := client.Database(mongoCfg.Database)
sensorRegistry.sensorCollection = weathersensorsDB.Collection(mongoCfg.Collection)
log.Print("successfully created mongodb connection")
return sensorRegistry, nil
}

View file

@ -58,6 +58,7 @@ func NewMqttSource(cfg config.MqttConfig) (*mqttWeatherSource, error) {
go source.publishDataValues()
log.Print("successfully connected to mqtt-broker")
return source, nil
}