1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-02 20:35:25 +02:00

feat(logging): replace all the loggers with zerolog EE-4186 (#7663)

This commit is contained in:
andres-portainer 2022-09-16 13:18:44 -03:00 committed by GitHub
parent 53025178ef
commit 36e7981ab7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
109 changed files with 1101 additions and 662 deletions

View file

@ -4,13 +4,14 @@ import (
"context"
"crypto/tls"
"errors"
"log"
"time"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/agent"
"github.com/portainer/portainer/api/crypto"
"github.com/portainer/portainer/api/dataservices"
"github.com/rs/zerolog/log"
)
// Service repesents a service to manage environment(endpoint) snapshots.
@ -149,7 +150,7 @@ func (service *Service) startSnapshotLoop() {
err := service.snapshotEndpoints()
if err != nil {
log.Printf("[ERROR] [internal,snapshot] [message: background schedule error (environment snapshot).] [error: %s]", err)
log.Error().Err(err).Msg("background schedule error (environment snapshot)")
}
for {
@ -157,10 +158,10 @@ func (service *Service) startSnapshotLoop() {
case <-ticker.C:
err := service.snapshotEndpoints()
if err != nil {
log.Printf("[ERROR] [internal,snapshot] [message: background schedule error (environment snapshot).] [error: %s]", err)
log.Error().Err(err).Msg("background schedule error (environment snapshot)")
}
case <-service.shutdownCtx.Done():
log.Println("[DEBUG] [internal,snapshot] [message: shutting down snapshotting]")
log.Debug().Msg("shutting down snapshotting")
ticker.Stop()
return
case interval := <-service.snapshotIntervalCh:
@ -184,13 +185,21 @@ func (service *Service) snapshotEndpoints() error {
latestEndpointReference, err := service.dataStore.Endpoint().Endpoint(endpoint.ID)
if latestEndpointReference == nil {
log.Printf("background schedule error (environment snapshot). Environment not found inside the database anymore (endpoint=%s, URL=%s) (err=%s)\n", endpoint.Name, endpoint.URL, err)
log.Debug().
Str("endpoint", endpoint.Name).
Str("URL", endpoint.URL).Err(err).
Msg("background schedule error (environment snapshot), environment not found inside the database anymore")
continue
}
latestEndpointReference.Status = portainer.EndpointStatusUp
if snapshotError != nil {
log.Printf("background schedule error (environment snapshot). Unable to create snapshot (endpoint=%s, URL=%s) (err=%s)\n", endpoint.Name, endpoint.URL, snapshotError)
log.Debug().
Str("endpoint", endpoint.Name).
Str("URL", endpoint.URL).Err(err).
Msg("background schedule error (environment snapshot), unable to create snapshot")
latestEndpointReference.Status = portainer.EndpointStatusDown
}
@ -200,7 +209,11 @@ func (service *Service) snapshotEndpoints() error {
err = service.dataStore.Endpoint().UpdateEndpoint(latestEndpointReference.ID, latestEndpointReference)
if err != nil {
log.Printf("background schedule error (environment snapshot). Unable to update environment (endpoint=%s, URL=%s) (err=%s)\n", endpoint.Name, endpoint.URL, err)
log.Debug().
Str("endpoint", endpoint.Name).
Str("URL", endpoint.URL).Err(err).
Msg("background schedule error (environment snapshot), unable to update environment")
continue
}
}