feat(pkg/logfile): support csv and xml logfile
This commit is contained in:
@ -23,6 +23,8 @@ func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compress
|
||||
logger.Info("Use compression: %v", compression)
|
||||
logger.Info("Round values: %v", round)
|
||||
|
||||
temperatureLogfile := logfile.New(cnf.Device.TemperatureLogfile)
|
||||
|
||||
ticker := time.Tick(cleanCacheInterval)
|
||||
|
||||
interrupt := make(chan os.Signal, 1)
|
||||
@ -38,7 +40,7 @@ func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compress
|
||||
// go sensor.ReadHumiditiesContinuously(cnf.GetHumiditySensors(config.ENABLED), humidityChannel, errorChannel)
|
||||
go sensor.ReadTemperaturesContinuously(childContext, cnf.GetTemperatureSensors(config.ENABLED), round, temperatureChannel, errorChannel)
|
||||
|
||||
temperatures := make([]*types.Temperature, 0)
|
||||
temperatureCache := make([]*types.Temperature, 0)
|
||||
|
||||
rgbLEDs := cnf.GetRGBLEDs(config.ENABLED)
|
||||
err := rgbled.Green(rgbLEDs)
|
||||
@ -57,12 +59,14 @@ func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compress
|
||||
logger.Error("Can not turn on blue info light: %v", err)
|
||||
}
|
||||
|
||||
err = logfile.WriteTemperatures(temperatures, cnf.Device.TemperatureLogfile, compression)
|
||||
//temperaturesLogfile,_ := temperatureLogfile.ReadTemperatures()
|
||||
|
||||
err = logfile.AppendTemperatures(temperatureLogfile, compression, temperatureCache)
|
||||
if err != nil {
|
||||
cancel()
|
||||
logger.Fatal("Can not save temperatures: %v", err)
|
||||
}
|
||||
temperatures = make([]*types.Temperature, 0)
|
||||
temperatureCache = make([]*types.Temperature, 0)
|
||||
|
||||
err = rgbled.Green(rgbLEDs)
|
||||
if err != nil {
|
||||
@ -70,7 +74,7 @@ func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compress
|
||||
}
|
||||
|
||||
case temperature, _ := <-temperatureChannel:
|
||||
temperatures = append(temperatures, temperature)
|
||||
temperatureCache = append(temperatureCache, temperature)
|
||||
|
||||
case killSignal := <-interrupt:
|
||||
logger.Warn("Daemon was interruped by system signal %v\n", killSignal)
|
||||
@ -83,13 +87,9 @@ func Start(cnf *config.Configuration, cleanCacheInterval time.Duration, compress
|
||||
}
|
||||
|
||||
logger.Warn("Save remaining temperature data from the cache")
|
||||
if compression {
|
||||
temperatures = logfile.CompressTemperature(temperatures)
|
||||
}
|
||||
|
||||
err = logfile.WriteTemperatures(temperatures, cnf.Device.TemperatureLogfile, compression)
|
||||
err = logfile.AppendTemperatures(temperatureLogfile, compression, temperatureCache)
|
||||
if err != nil {
|
||||
logger.Fatal("Can not save temperatures: %v", err)
|
||||
logger.Fatal("%v", err)
|
||||
}
|
||||
|
||||
return
|
||||
|
Reference in New Issue
Block a user