diff --git a/main.go b/main.go index 50d5188..50514fc 100644 --- a/main.go +++ b/main.go @@ -24,7 +24,7 @@ type Config struct { Port string Username string Password string - Clientid string + ClientId string } type App struct { @@ -41,7 +41,7 @@ func NewApp(conf Config) *App { Port: conf.Port, Username: conf.Username, Password: conf.Password, - ClientID: conf.Clientid, + ClientID: conf.ClientId, CleanSession: true, AutoReconnect: true, Retained: false, @@ -92,19 +92,19 @@ func (app *App) subscribe( func (app *App) runTicker() { ticker := time.NewTicker(60 * time.Second) - // logger := zerolog.Ctx(app.ctx).With().Str("action", "ticker").Logger() - // logger.Info().Msg("Start ticker") + logger := zerolog.Ctx(app.ctx).With().Str("action", "ticker").Logger() + logger.Info().Msg("Start ticker") - // ctx := logger.WithContext(app.ctx) go func() { for { select { case <-app.ctx.Done(): return - // case t := <-ticker.C: - case <-ticker.C: + case t := <-ticker.C: + // case <-ticker.C: ctx, cancel := context.WithCancel(app.ctx) - // logger.Info().Time("at", t).Msg("Tick") + ctx = logger.WithContext(app.ctx) + logger.Info().Time("at", t).Msg("Tick") app.DeviceManager.CheckAll(ctx) cancel() } @@ -265,7 +265,7 @@ func main() { Port: *port, Username: *username, Password: *password, - Clientid: *clientid, + ClientId: *clientid, } app := NewApp(config) diff --git a/pkg/device/device_manager.go b/pkg/device/device_manager.go index b0b3607..aadd8b9 100644 --- a/pkg/device/device_manager.go +++ b/pkg/device/device_manager.go @@ -3,7 +3,6 @@ package device import ( "context" "fmt" - "os" "git.quimbo.fr/nicolas/mqtt" "github.com/rs/zerolog" @@ -88,11 +87,10 @@ func (m *DeviceManager) Check(ctx context.Context, name string) error { } func (m *DeviceManager) CheckAll(ctx context.Context) { - // func (m *DeviceManager) CheckAll() { - logger := zerolog.New(os.Stdout) + logger := zerolog.Ctx(ctx) for _, device := range m.devices { - if err := device.CheckSetpoint(logger, m.PubChan); err != nil { + if err := device.CheckSetpoint(*logger, m.PubChan); err != nil { logger.Error().Err(err).Msg("") } }