add more logging
This commit is contained in:
parent
791518f3be
commit
ff28e70c31
4 changed files with 10 additions and 0 deletions
4
main.go
4
main.go
|
@ -16,6 +16,8 @@ var weatherSource weathersource.WeatherSource
|
||||||
var weatherAPI api.WeatherAPI
|
var weatherAPI api.WeatherAPI
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
log.SetOutput(os.Stdout)
|
||||||
|
|
||||||
//setup new sensorRegistry -> MongodbSensorRegistry
|
//setup new sensorRegistry -> MongodbSensorRegistry
|
||||||
var err error
|
var err error
|
||||||
if sensorRegistry, err = storage.NewMongodbSensorRegistry(config.MongoConfiguration); err != nil {
|
if sensorRegistry, err = storage.NewMongodbSensorRegistry(config.MongoConfiguration); err != nil {
|
||||||
|
@ -44,6 +46,7 @@ func main() {
|
||||||
defer weatherAPI.Close()
|
defer weatherAPI.Close()
|
||||||
weatherAPI.AddNewWeatherDataCallback(handleNewWeatherData)
|
weatherAPI.AddNewWeatherDataCallback(handleNewWeatherData)
|
||||||
|
|
||||||
|
log.Print("Application is running")
|
||||||
err = weatherAPI.Start()
|
err = weatherAPI.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -54,6 +57,7 @@ func main() {
|
||||||
func handleNewWeatherData(wd storage.WeatherData) error {
|
func handleNewWeatherData(wd storage.WeatherData) error {
|
||||||
_, err := sensorRegistry.ResolveSensorById(wd.SensorId)
|
_, err := sensorRegistry.ResolveSensorById(wd.SensorId)
|
||||||
if !config.AllowUnregisteredSensors && err != nil {
|
if !config.AllowUnregisteredSensors && err != nil {
|
||||||
|
log.Print("discarded invalid weatherdata")
|
||||||
return fmt.Errorf("could not resolve sensor")
|
return fmt.Errorf("could not resolve sensor")
|
||||||
}
|
}
|
||||||
weatherStorage.Save(wd)
|
weatherStorage.Save(wd)
|
||||||
|
|
|
@ -3,6 +3,7 @@ package storage
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
"weather-data/config"
|
"weather-data/config"
|
||||||
|
|
||||||
|
@ -23,6 +24,7 @@ func NewInfluxStorage(cfg config.InfluxConfig) (*influxStorage, error) {
|
||||||
influx.config = cfg
|
influx.config = cfg
|
||||||
influx.client = influxdb2.NewClient(cfg.Host, cfg.Token)
|
influx.client = influxdb2.NewClient(cfg.Host, cfg.Token)
|
||||||
influx.measurement = "data"
|
influx.measurement = "data"
|
||||||
|
log.Print("Successfully created influx-client")
|
||||||
return influx, nil
|
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 := storage.client.WriteAPI(storage.config.Organization, storage.config.Bucket)
|
||||||
writeAPI.WritePoint(datapoint)
|
writeAPI.WritePoint(datapoint)
|
||||||
|
log.Print("Written weather data point to influx-db")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,8 @@ func NewMongodbSensorRegistry(mongoCfg config.MongoConfig) (*mongodbSensorRegist
|
||||||
weathersensorsDB := client.Database(mongoCfg.Database)
|
weathersensorsDB := client.Database(mongoCfg.Database)
|
||||||
sensorRegistry.sensorCollection = weathersensorsDB.Collection(mongoCfg.Collection)
|
sensorRegistry.sensorCollection = weathersensorsDB.Collection(mongoCfg.Collection)
|
||||||
|
|
||||||
|
log.Print("successfully created mongodb connection")
|
||||||
|
|
||||||
return sensorRegistry, nil
|
return sensorRegistry, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,7 @@ func NewMqttSource(cfg config.MqttConfig) (*mqttWeatherSource, error) {
|
||||||
|
|
||||||
go source.publishDataValues()
|
go source.publishDataValues()
|
||||||
|
|
||||||
|
log.Print("successfully connected to mqtt-broker")
|
||||||
return source, nil
|
return source, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue