1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-24 22:39:18 +01:00

chore: uses zerolog instead of logrus (#3203)

This commit is contained in:
Amir Raminfar
2024-08-14 10:04:18 -07:00
committed by GitHub
parent 37f0249065
commit 077eeb7917
38 changed files with 278 additions and 265 deletions

View File

@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"path/filepath"
"sort"
"strconv"
"strings"
@@ -21,7 +20,7 @@ import (
"github.com/docker/docker/api/types/system"
"github.com/docker/docker/client"
log "github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
)
type StdType int
@@ -83,7 +82,7 @@ type httpClient struct {
func NewClient(cli DockerCLI, filters filters.Args, host Host) Client {
info, err := cli.Info(context.Background())
if err != nil {
log.Errorf("unable to get docker info: %v", err)
log.Error().Err(err).Msg("Failed to get docker info")
}
host.NCPU = info.NCPU
@@ -107,7 +106,7 @@ func NewLocalClient(f map[string][]string, hostname string) (Client, error) {
}
}
log.Debugf("filterArgs = %v", filterArgs)
log.Debug().Interface("filterArgs", filterArgs).Msg("Creating local client")
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
@@ -149,10 +148,10 @@ func NewRemoteClient(f map[string][]string, host Host) (Client, error) {
}
}
log.Debugf("filterArgs = %v", filterArgs)
log.Debug().Interface("filterArgs", filterArgs).Msg("Creating remote client")
if host.URL.Scheme != "tcp" {
log.Fatal("Only tcp scheme is supported")
return nil, fmt.Errorf("invalid scheme: %s", host.URL.Scheme)
}
opts := []client.Opt{
@@ -160,10 +159,10 @@ func NewRemoteClient(f map[string][]string, host Host) (Client, error) {
}
if host.ValidCerts {
log.Debugf("Using TLS client config with certs at: %s", filepath.Dir(host.CertPath))
log.Debug().Str("caCertPath", host.CACertPath).Str("certPath", host.CertPath).Str("keyPath", host.KeyPath).Msg("Using TLS for remote client")
opts = append(opts, client.WithTLSClientConfig(host.CACertPath, host.CertPath, host.KeyPath))
} else {
log.Debugf("No valid certs found, using plain TCP")
log.Debug().Msg("Not using TLS for remote client")
}
opts = append(opts, client.WithAPIVersionNegotiation())
@@ -181,7 +180,7 @@ func NewRemoteClient(f map[string][]string, host Host) (Client, error) {
// Finds a container by id, skipping the filters
func (d *httpClient) FindContainer(id string) (Container, error) {
log.Debugf("finding container with id: %s", id)
log.Debug().Str("id", id).Msg("Finding container")
if json, err := d.cli.ContainerInspect(context.Background(), id); err == nil {
return newContainerFromJSON(json, d.host.ID), nil
} else {
@@ -204,7 +203,7 @@ func (d *httpClient) ContainerActions(action ContainerAction, containerID string
}
func (d *httpClient) ListContainers() ([]Container, error) {
log.Debugf("listing containers with filters: %v", d.filters)
log.Debug().Interface("filter", d.filters).Str("host", d.host.Name).Msg("Listing containers")
containerListOptions := container.ListOptions{
Filters: d.filters,
All: true,
@@ -277,7 +276,7 @@ func (d *httpClient) ContainerStats(ctx context.Context, id string, stats chan<-
}
func (d *httpClient) ContainerLogs(ctx context.Context, id string, since time.Time, stdType StdType) (io.ReadCloser, error) {
log.WithField("id", id).WithField("since", since).WithField("stdType", stdType).Debug("streaming logs for container")
log.Debug().Str("id", id).Time("since", since).Stringer("stdType", stdType).Str("host", d.host.Name).Msg("Streaming logs for container")
sinceQuery := since.Add(-50 * time.Millisecond).Format(time.RFC3339Nano)
options := container.LogsOptions{
@@ -320,6 +319,7 @@ func (d *httpClient) ContainerEvents(ctx context.Context, messages chan<- Contai
}
func (d *httpClient) ContainerLogsBetweenDates(ctx context.Context, id string, from time.Time, to time.Time, stdType StdType) (io.ReadCloser, error) {
log.Debug().Str("id", id).Time("from", from).Time("to", to).Stringer("stdType", stdType).Str("host", d.host.Name).Msg("Fetching logs between dates for container")
options := container.LogsOptions{
ShowStdout: stdType&STDOUT != 0,
ShowStderr: stdType&STDERR != 0,
@@ -328,8 +328,6 @@ func (d *httpClient) ContainerLogsBetweenDates(ctx context.Context, id string, f
Until: to.Format(time.RFC3339Nano),
}
log.Debugf("fetching logs from Docker with option: %+v", options)
reader, err := d.cli.ContainerLogs(ctx, id, options)
if err != nil {
return nil, err