fix(pkg/server): logging and save values into postgres
This commit is contained in:
@ -86,7 +86,7 @@ func PrintSensors(cnf *config.Configuration, w io.Writer) error {
|
||||
}
|
||||
|
||||
if sensor.I2CAddress != nil {
|
||||
fmt.Fprintf(tw, "%v\t", string(*sensor.I2CAddress))
|
||||
fmt.Fprintf(tw, "%#v\t", *sensor.I2CAddress)
|
||||
} else {
|
||||
fmt.Fprintf(tw, "\t")
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"context"
|
||||
"net/url"
|
||||
"sync"
|
||||
|
||||
@ -56,7 +56,7 @@ func (cs *cacheStore) WriteToEndpoint() error {
|
||||
case "file":
|
||||
return cs.logfile()
|
||||
case "postgres":
|
||||
return fmt.Errorf("Not yet implemented to store values into a postgres database")
|
||||
return cs.postgres()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -91,3 +91,8 @@ func (cs *cacheStore) logfile() error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cs *cacheStore) postgres() error {
|
||||
ctx := context.Background()
|
||||
return storage.Write(ctx, cs.cache, cs.URL)
|
||||
}
|
||||
|
@ -15,9 +15,13 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
flogger = logger.NewDefaultLogger(logger.LogLevelDebug)
|
||||
flogger = logger.NewSilentLogger()
|
||||
)
|
||||
|
||||
func SetLogger(logger logger.Logger) {
|
||||
flogger = logger
|
||||
}
|
||||
|
||||
// Start the daemon
|
||||
func Start(cnf *config.Configuration, cacheSize uint, compression bool, round float64) error {
|
||||
|
||||
@ -129,7 +133,10 @@ func Start(cnf *config.Configuration, cacheSize uint, compression bool, round fl
|
||||
flogger.Fatal("Received a fatal error: %v", fatal)
|
||||
case <-interruptChannel:
|
||||
flogger.Debug("Write %v cached values into storage endpoint", cache.Size())
|
||||
cache.WriteToEndpoint()
|
||||
err := cache.WriteToEndpoint()
|
||||
if err != nil {
|
||||
flogger.Error("%v", err)
|
||||
}
|
||||
flogger.Debug("Close context")
|
||||
cancel()
|
||||
flogger.Debug("Close channels")
|
||||
|
Reference in New Issue
Block a user