mirror of
https://github.com/portainer/portainer.git
synced 2025-07-25 08:19:40 +02:00
feat(logging): replace all the loggers with zerolog EE-4186 (#7663)
This commit is contained in:
parent
53025178ef
commit
36e7981ab7
109 changed files with 1101 additions and 662 deletions
|
@ -3,8 +3,6 @@ package http
|
|||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
@ -64,6 +62,8 @@ import (
|
|||
"github.com/portainer/portainer/api/kubernetes/cli"
|
||||
"github.com/portainer/portainer/api/scheduler"
|
||||
stackdeployer "github.com/portainer/portainer/api/stacks"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
// Server implements the portainer.Server interface
|
||||
|
@ -319,21 +319,22 @@ func (server *Server) Start() error {
|
|||
handler := adminMonitor.WithRedirect(offlineGate.WaitingMiddleware(time.Minute, server.Handler))
|
||||
if server.HTTPEnabled {
|
||||
go func() {
|
||||
log.Printf("[INFO] [http,server] [message: starting HTTP server on port %s]", server.BindAddress)
|
||||
log.Info().Str("bind_address", server.BindAddress).Msg("starting HTTP server")
|
||||
httpServer := &http.Server{
|
||||
Addr: server.BindAddress,
|
||||
Handler: handler,
|
||||
}
|
||||
|
||||
go shutdown(server.ShutdownCtx, httpServer)
|
||||
|
||||
err := httpServer.ListenAndServe()
|
||||
if err != nil && err != http.ErrServerClosed {
|
||||
log.Printf("[ERROR] [message: http server failed] [error: %s]", err)
|
||||
log.Error().Err(err).Msg("HTTP server failed to start")
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
log.Printf("[INFO] [http,server] [message: starting HTTPS server on port %s]", server.BindAddressHTTPS)
|
||||
log.Info().Str("bind_address", server.BindAddressHTTPS).Msg("starting HTTPS server")
|
||||
httpsServer := &http.Server{
|
||||
Addr: server.BindAddressHTTPS,
|
||||
Handler: handler,
|
||||
|
@ -345,18 +346,21 @@ func (server *Server) Start() error {
|
|||
}
|
||||
|
||||
go shutdown(server.ShutdownCtx, httpsServer)
|
||||
|
||||
return httpsServer.ListenAndServeTLS("", "")
|
||||
}
|
||||
|
||||
func shutdown(shutdownCtx context.Context, httpServer *http.Server) {
|
||||
<-shutdownCtx.Done()
|
||||
|
||||
log.Println("[DEBUG] [http,server] [message: shutting down http server]")
|
||||
log.Debug().Msg("shutting down the HTTP server")
|
||||
shutdownTimeout, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
|
||||
err := httpServer.Shutdown(shutdownTimeout)
|
||||
if err != nil {
|
||||
fmt.Printf("[ERROR] [http,server] [message: failed shutdown http server] [error: %s]", err)
|
||||
log.Error().
|
||||
Err(err).
|
||||
Msg("failed to shut down the HTTP server")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue