From abeaf556eff9214daf579b53753a4ead94f4546f Mon Sep 17 00:00:00 2001 From: Pierre Gimalac Date: Wed, 4 Dec 2024 19:17:34 +0100 Subject: [PATCH] chore: add seelog aliases in pkg/util/log and use them everywhere else --- .golangci.yml | 6 + cmd/agent/common/common_windows.go | 5 +- .../clcrunnerapi/clc_runner_server.go | 4 +- cmd/cluster-agent/admission/server.go | 3 +- cmd/cluster-agent/api/server.go | 4 +- cmd/security-agent/api/server.go | 4 +- .../test/testsuite/config_set_test.go | 4 +- comp/api/api/apiimpl/server.go | 5 +- comp/core/log/mock/go.mod | 2 +- comp/core/log/mock/mock.go | 6 +- .../serverDebug/serverdebugimpl/debug.go | 8 +- .../netflow/flowaggregator/aggregator_test.go | 3 +- comp/netflow/goflowlib/logger.go | 15 +- .../npcollectorimpl/npcollector_test.go | 9 +- .../pathteststore/pathteststore_test.go | 3 +- .../rcclient/rcclientimpl/rcclient_test.go | 3 +- comp/trace/config/config_test.go | 4 +- pkg/clusteragent/api/leader_forwarder.go | 5 +- pkg/collector/corechecks/ebpf/ebpf.go | 9 +- .../corechecks/ebpf/probe/ebpfcheck/probe.go | 3 +- .../snmp/internal/checkconfig/config.go | 3 +- .../config_validate_enrich_test.go | 5 +- .../snmp/internal/devicecheck/devicecheck.go | 7 +- .../snmp/internal/fetch/fetch_column.go | 5 +- .../snmp/internal/fetch/fetch_scalar.go | 3 +- .../snmp/internal/fetch/fetch_test.go | 3 +- .../internal/profile/profile_resolver_test.go | 3 +- .../internal/profile/profile_yaml_test.go | 10 +- .../report/report_device_metadata_test.go | 3 +- .../internal/report/report_metrics_test.go | 7 +- .../snmp/internal/report/report_utils_test.go | 5 +- .../snmp/internal/session/session.go | 3 +- .../snmp/internal/session/session_test.go | 5 +- pkg/collector/python/memory.go | 6 +- pkg/ebpf/ebpftest/fail_log.go | 3 +- pkg/ebpf/ebpftest/log.go | 3 +- pkg/ebpf/map_cleaner_test.go | 3 +- pkg/ebpf/verifier/stats_test.go | 3 +- pkg/gohai/cpu/util_linux.go | 2 +- pkg/gohai/filesystem/filesystem_nix.go | 4 +- pkg/gohai/go.mod | 2 +- pkg/gohai/memory/memory_linux.go | 2 +- pkg/gohai/platform/platform_darwin.go | 5 +- pkg/gohai/processes/gops/process_info.go | 6 +- pkg/logs/tailers/windowsevent/tailer_test.go | 4 +- pkg/network/encoding/marshal/usm.go | 4 +- pkg/network/go/bininspect/symbols.go | 6 +- .../netlink/conntrack_integration_test.go | 3 +- pkg/network/netlink/conntracker.go | 5 +- pkg/network/netlink/consumer.go | 3 +- pkg/network/port_test.go | 3 +- pkg/network/protocols/events/consumer.go | 4 +- pkg/network/protocols/http/telemetry.go | 4 +- pkg/network/protocols/http2/telemetry.go | 4 +- pkg/network/protocols/kafka/telemetry.go | 4 +- pkg/network/protocols/postgres/telemetry.go | 4 +- pkg/network/state.go | 3 +- pkg/network/tracer/connection/ebpf_tracer.go | 3 +- pkg/network/tracer/ebpf_conntracker.go | 9 +- pkg/network/tracer/process_cache.go | 3 +- pkg/network/tracer/tracer.go | 7 +- pkg/network/tracer/tracer_test.go | 3 +- pkg/network/usm/ebpf_gotls.go | 3 +- pkg/network/usm/monitor_test.go | 3 +- .../usm/tests/tracer_classification_test.go | 3 +- pkg/network/usm/utils/file_registry.go | 3 +- pkg/process/metadata/parser/service.go | 5 +- pkg/process/monitor/process_monitor.go | 5 +- pkg/process/procutil/process_linux_test.go | 1 + pkg/security/seclog/logger.go | 4 +- pkg/security/tests/main_test.go | 4 +- pkg/security/tests/module_tester_linux.go | 11 +- pkg/serverless/daemon/routes_test.go | 3 +- pkg/snmp/gosnmplib/gosnmp_log_test.go | 3 +- pkg/trace/go.mod | 2 +- .../remote_config_handler.go | 5 +- .../remote_config_handler_test.go | 13 +- pkg/util/grpc/agent_client_test.go | 3 +- pkg/util/grpc/go.mod | 2 +- .../controllers/wpa_controller_test.go | 4 +- pkg/util/log/levels.go | 47 ++++++ pkg/util/log/log.go | 143 +++++++++--------- pkg/util/log/log_bench_test.go | 16 +- pkg/util/log/log_not_serverless_test.go | 3 +- pkg/util/log/log_serverless_test.go | 3 +- pkg/util/log/log_test.go | 84 +++++----- pkg/util/log/log_test_init.go | 4 +- pkg/util/log/logger.go | 35 +++++ pkg/util/log/setup/log.go | 16 +- pkg/util/log/zap/zapcore.go | 13 +- .../subscription/subscription_test.go | 9 +- pkg/util/winutil/go.mod | 2 +- 92 files changed, 370 insertions(+), 364 deletions(-) create mode 100644 pkg/util/log/levels.go create mode 100644 pkg/util/log/logger.go diff --git a/.golangci.yml b/.golangci.yml index 0358a505b01187..320c25ce206a71 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -607,6 +607,12 @@ linters-settings: desc: "Not really forbidden to use, but it is usually imported by mistake instead of github.com/stretchr/testify/assert, and confusing since it actually has the behavior of github.com/stretchr/testify/require" - pkg: "debug/elf" desc: "prefer pkg/util/safeelf to prevent panics during parsing" + logger: + files: + - "!**/pkg/util/log/**" + deny: + - pkg: "github.com/cihub/seelog" + desc: "seelog should not be used directly. Use `pkg/util/log` instead." errcheck: exclude-functions: diff --git a/cmd/agent/common/common_windows.go b/cmd/agent/common/common_windows.go index 852d4d77d5ccda..33d215dccc84a6 100644 --- a/cmd/agent/common/common_windows.go +++ b/cmd/agent/common/common_windows.go @@ -9,13 +9,14 @@ import ( "os" "path/filepath" + //nolint:depguard // creating a logger from a seelog config + "github.com/cihub/seelog" + pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" "github.com/DataDog/datadog-agent/pkg/util/defaultpaths" "github.com/DataDog/datadog-agent/pkg/util/log" "github.com/DataDog/datadog-agent/pkg/util/winutil" "github.com/DataDog/datadog-agent/pkg/util/winutil/messagestrings" - - "github.com/cihub/seelog" ) // ServiceName is the name of the Windows Service the agent runs as diff --git a/cmd/agent/subcommands/run/internal/clcrunnerapi/clc_runner_server.go b/cmd/agent/subcommands/run/internal/clcrunnerapi/clc_runner_server.go index 9b763d3a8b1dfc..7554f755a2d1b1 100644 --- a/cmd/agent/subcommands/run/internal/clcrunnerapi/clc_runner_server.go +++ b/cmd/agent/subcommands/run/internal/clcrunnerapi/clc_runner_server.go @@ -19,7 +19,6 @@ import ( "net/http" "time" - "github.com/cihub/seelog" "github.com/gorilla/mux" v1 "github.com/DataDog/datadog-agent/cmd/agent/subcommands/run/internal/clcrunnerapi/v1" @@ -27,6 +26,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/api/security" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" + "github.com/DataDog/datadog-agent/pkg/util/log" pkglogsetup "github.com/DataDog/datadog-agent/pkg/util/log/setup" ) @@ -85,7 +85,7 @@ func StartCLCRunnerServer(extraHandlers map[string]http.Handler, ac autodiscover } // Use a stack depth of 4 on top of the default one to get a relevant filename in the stdlib - logWriter, _ := pkglogsetup.NewLogWriter(4, seelog.WarnLvl) + logWriter, _ := pkglogsetup.NewLogWriter(4, log.WarnLvl) srv := &http.Server{ Handler: r, diff --git a/cmd/cluster-agent/admission/server.go b/cmd/cluster-agent/admission/server.go index ea53230e19a35e..86b237001037b3 100644 --- a/cmd/cluster-agent/admission/server.go +++ b/cmd/cluster-agent/admission/server.go @@ -18,7 +18,6 @@ import ( "net/http" "time" - "github.com/cihub/seelog" admiv1 "k8s.io/api/admission/v1" admiv1beta1 "k8s.io/api/admission/v1beta1" admissionregistrationv1 "k8s.io/api/admissionregistration/v1" @@ -117,7 +116,7 @@ func (s *Server) Run(mainCtx context.Context, client kubernetes.Interface) error tlsMinVersion = tls.VersionTLS10 } - logWriter, _ := pkglogsetup.NewTLSHandshakeErrorWriter(4, seelog.WarnLvl) + logWriter, _ := pkglogsetup.NewTLSHandshakeErrorWriter(4, log.WarnLvl) server := &http.Server{ Addr: fmt.Sprintf(":%d", pkgconfigsetup.Datadog().GetInt("admission_controller.port")), Handler: s.mux, diff --git a/cmd/cluster-agent/api/server.go b/cmd/cluster-agent/api/server.go index 7b2c26fb1d8d5e..37efad4d900ddf 100644 --- a/cmd/cluster-agent/api/server.go +++ b/cmd/cluster-agent/api/server.go @@ -25,7 +25,6 @@ import ( languagedetection "github.com/DataDog/datadog-agent/cmd/cluster-agent/api/v1/languagedetection" - "github.com/cihub/seelog" "github.com/gorilla/mux" grpc_auth "github.com/grpc-ecosystem/go-grpc-middleware/auth" "google.golang.org/grpc" @@ -44,6 +43,7 @@ import ( pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/core" grpcutil "github.com/DataDog/datadog-agent/pkg/util/grpc" + "github.com/DataDog/datadog-agent/pkg/util/log" pkglogsetup "github.com/DataDog/datadog-agent/pkg/util/log/setup" ) @@ -113,7 +113,7 @@ func StartServer(ctx context.Context, w workloadmeta.Component, taggerComp tagge } // Use a stack depth of 4 on top of the default one to get a relevant filename in the stdlib - logWriter, _ := pkglogsetup.NewTLSHandshakeErrorWriter(4, seelog.WarnLvl) + logWriter, _ := pkglogsetup.NewTLSHandshakeErrorWriter(4, log.WarnLvl) authInterceptor := grpcutil.AuthInterceptor(func(token string) (interface{}, error) { if token != util.GetDCAAuthToken() { diff --git a/cmd/security-agent/api/server.go b/cmd/security-agent/api/server.go index 3b44b83e39436b..e776628e5ccd49 100644 --- a/cmd/security-agent/api/server.go +++ b/cmd/security-agent/api/server.go @@ -20,7 +20,6 @@ import ( "net/http" "time" - "github.com/cihub/seelog" "github.com/gorilla/mux" "github.com/DataDog/datadog-agent/cmd/security-agent/api/agent" @@ -30,6 +29,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/api/security" "github.com/DataDog/datadog-agent/pkg/api/util" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" + "github.com/DataDog/datadog-agent/pkg/util/log" pkglogsetup "github.com/DataDog/datadog-agent/pkg/util/log/setup" ) @@ -90,7 +90,7 @@ func (s *Server) Start() error { } // Use a stack depth of 4 on top of the default one to get a relevant filename in the stdlib - logWriter, _ := pkglogsetup.NewLogWriter(4, seelog.ErrorLvl) + logWriter, _ := pkglogsetup.NewLogWriter(4, log.ErrorLvl) srv := &http.Server{ Handler: r, diff --git a/cmd/trace-agent/test/testsuite/config_set_test.go b/cmd/trace-agent/test/testsuite/config_set_test.go index ee2065f63c7a23..1a9175490aca21 100644 --- a/cmd/trace-agent/test/testsuite/config_set_test.go +++ b/cmd/trace-agent/test/testsuite/config_set_test.go @@ -11,10 +11,10 @@ import ( "testing" "time" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "github.com/DataDog/datadog-agent/cmd/trace-agent/test" + "github.com/DataDog/datadog-agent/pkg/util/log" ) func TestConfigSetHandlerUnauthenticated(t *testing.T) { @@ -36,7 +36,7 @@ func TestConfigSetHandlerUnauthenticated(t *testing.T) { assert.NotContains(t, logstr, "| DEBUG |") assert.Contains(t, logstr, "| INFO |") - resp, err := r.DoReq(fmt.Sprintf("config/set?log_level=%s", seelog.WarnStr), http.MethodPost, nil) + resp, err := r.DoReq(fmt.Sprintf("config/set?log_level=%s", log.WarnStr), http.MethodPost, nil) if err != nil { t.Fatal(err) } diff --git a/comp/api/api/apiimpl/server.go b/comp/api/api/apiimpl/server.go index b4d42f1178218e..762a67b8a4a63c 100644 --- a/comp/api/api/apiimpl/server.go +++ b/comp/api/api/apiimpl/server.go @@ -12,17 +12,14 @@ import ( "net" "net/http" - "github.com/cihub/seelog" - "github.com/DataDog/datadog-agent/comp/api/api/apiimpl/observability" - "github.com/DataDog/datadog-agent/pkg/util/log" pkglogsetup "github.com/DataDog/datadog-agent/pkg/util/log/setup" ) func startServer(listener net.Listener, srv *http.Server, name string) { // Use a stack depth of 4 on top of the default one to get a relevant filename in the stdlib - logWriter, _ := pkglogsetup.NewLogWriter(5, seelog.ErrorLvl) + logWriter, _ := pkglogsetup.NewLogWriter(5, log.ErrorLvl) srv.ErrorLog = stdLog.New(logWriter, fmt.Sprintf("Error from the Agent HTTP server '%s': ", name), 0) // log errors to seelog diff --git a/comp/core/log/mock/go.mod b/comp/core/log/mock/go.mod index 96c709d9f2f328..442fc0550bf69e 100644 --- a/comp/core/log/mock/go.mod +++ b/comp/core/log/mock/go.mod @@ -33,7 +33,6 @@ require ( github.com/DataDog/datadog-agent/comp/core/log/def v0.0.0-00010101000000-000000000000 github.com/DataDog/datadog-agent/pkg/util/log v0.59.0 github.com/DataDog/datadog-agent/pkg/util/log/setup v0.0.0-00010101000000-000000000000 - github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 ) require ( @@ -42,6 +41,7 @@ require ( github.com/DataDog/datadog-agent/pkg/config/teeconfig v0.60.0-devel // indirect github.com/DataDog/datadog-agent/pkg/util/scrubber v0.59.0 // indirect github.com/DataDog/viper v1.13.5 // indirect + github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect github.com/fsnotify/fsnotify v1.8.0 // indirect github.com/hashicorp/hcl v1.0.1-vault-5 // indirect github.com/magiconair/properties v1.8.7 // indirect diff --git a/comp/core/log/mock/mock.go b/comp/core/log/mock/mock.go index b3dde056dcb8f5..9e29cdf5fb65a9 100644 --- a/comp/core/log/mock/mock.go +++ b/comp/core/log/mock/mock.go @@ -10,8 +10,6 @@ import ( "strings" "testing" - "github.com/cihub/seelog" - log "github.com/DataDog/datadog-agent/comp/core/log/def" pkglog "github.com/DataDog/datadog-agent/pkg/util/log" @@ -37,7 +35,7 @@ func (tbw *tbWriter) Write(p []byte) (n int, err error) { // New returns a new mock for the log Component func New(t testing.TB) log.Component { // Build a logger that only logs to t.Log(..) - iface, err := seelog.LoggerFromWriterWithMinLevelAndFormat(&tbWriter{t}, seelog.TraceLvl, + iface, err := pkglog.LoggerFromWriterWithMinLevelAndFormat(&tbWriter{t}, pkglog.TraceLvl, "%Date(2006-01-02 15:04:05 MST) | %LEVEL | (%ShortFilePath:%Line in %FuncShort) | %ExtraTextContext%Msg%n") if err != nil { t.Fatal(err.Error()) @@ -45,7 +43,7 @@ func New(t testing.TB) log.Component { t.Cleanup(func() { // stop using the logger to avoid a race condition - pkglog.ChangeLogLevel(seelog.Default, "debug") + pkglog.ChangeLogLevel(pkglog.Default(), "debug") iface.Flush() }) diff --git a/comp/dogstatsd/serverDebug/serverdebugimpl/debug.go b/comp/dogstatsd/serverDebug/serverdebugimpl/debug.go index 90c528919bef17..4a8a7a5926ba43 100644 --- a/comp/dogstatsd/serverDebug/serverdebugimpl/debug.go +++ b/comp/dogstatsd/serverDebug/serverdebugimpl/debug.go @@ -16,7 +16,6 @@ import ( "time" "github.com/benbjohnson/clock" - slog "github.com/cihub/seelog" "go.uber.org/atomic" "go.uber.org/fx" @@ -31,6 +30,7 @@ import ( "github.com/DataDog/datadog-agent/pkg/tagset" "github.com/DataDog/datadog-agent/pkg/util/defaultpaths" "github.com/DataDog/datadog-agent/pkg/util/fxutil" + pkglog "github.com/DataDog/datadog-agent/pkg/util/log" pkglogsetup "github.com/DataDog/datadog-agent/pkg/util/log/setup" ) @@ -71,7 +71,7 @@ type serverDebugImpl struct { clock clock.Clock tagsAccumulator *tagset.HashingTagsAccumulator // dogstatsdDebugLogger is an instance of the logger config that can be used to create new logger for dogstatsd-stats metrics - dogstatsdDebugLogger slog.LoggerInterface + dogstatsdDebugLogger pkglog.LoggerInterface } // NewServerlessServerDebug creates a new instance of serverDebug.Component @@ -279,9 +279,9 @@ func (d *serverDebugImpl) disableMetricsStats() { } // build a local dogstatsd logger and bubbling up any errors -func (d *serverDebugImpl) getDogstatsdDebug(cfg model.Reader) slog.LoggerInterface { +func (d *serverDebugImpl) getDogstatsdDebug(cfg model.Reader) pkglog.LoggerInterface { - var dogstatsdLogger slog.LoggerInterface + var dogstatsdLogger pkglog.LoggerInterface // Configuring the log file path logFile := cfg.GetString("dogstatsd_log_file") diff --git a/comp/netflow/flowaggregator/aggregator_test.go b/comp/netflow/flowaggregator/aggregator_test.go index 181915ab3f628f..3ba87f0a126396 100644 --- a/comp/netflow/flowaggregator/aggregator_test.go +++ b/comp/netflow/flowaggregator/aggregator_test.go @@ -18,7 +18,6 @@ import ( "testing" "time" - "github.com/cihub/seelog" "github.com/gogo/protobuf/proto" "github.com/golang/mock/gomock" "github.com/prometheus/client_golang/prometheus" @@ -336,7 +335,7 @@ func TestFlowAggregator_flush_submitCollectorMetrics_error(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := ddlog.LoggerFromWriterWithMinLevelAndFormat(w, ddlog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") require.NoError(t, err) ddlog.SetupLogger(l, "debug") diff --git a/comp/netflow/goflowlib/logger.go b/comp/netflow/goflowlib/logger.go index 62035bcd052e5c..e0a61338c7c46d 100644 --- a/comp/netflow/goflowlib/logger.go +++ b/comp/netflow/goflowlib/logger.go @@ -6,20 +6,19 @@ package goflowlib import ( - "github.com/cihub/seelog" "github.com/sirupsen/logrus" log "github.com/DataDog/datadog-agent/comp/core/log/def" ddlog "github.com/DataDog/datadog-agent/pkg/util/log" ) -var ddLogToLogrusLevel = map[seelog.LogLevel]logrus.Level{ - seelog.TraceLvl: logrus.TraceLevel, - seelog.DebugLvl: logrus.DebugLevel, - seelog.InfoLvl: logrus.InfoLevel, - seelog.WarnLvl: logrus.WarnLevel, - seelog.ErrorLvl: logrus.ErrorLevel, - seelog.CriticalLvl: logrus.FatalLevel, +var ddLogToLogrusLevel = map[ddlog.LogLevel]logrus.Level{ + ddlog.TraceLvl: logrus.TraceLevel, + ddlog.DebugLvl: logrus.DebugLevel, + ddlog.InfoLvl: logrus.InfoLevel, + ddlog.WarnLvl: logrus.WarnLevel, + ddlog.ErrorLvl: logrus.ErrorLevel, + ddlog.CriticalLvl: logrus.FatalLevel, } // GetLogrusLevel returns logrus log level from log.GetLogLevel() diff --git a/comp/networkpath/npcollector/npcollectorimpl/npcollector_test.go b/comp/networkpath/npcollector/npcollectorimpl/npcollector_test.go index 6b6416e0d47ae0..a5bdcd86f7e4f2 100644 --- a/comp/networkpath/npcollector/npcollectorimpl/npcollector_test.go +++ b/comp/networkpath/npcollector/npcollectorimpl/npcollector_test.go @@ -19,7 +19,6 @@ import ( "time" model "github.com/DataDog/agent-payload/v5/process" - "github.com/cihub/seelog" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" @@ -46,7 +45,7 @@ func Test_NpCollector_StartAndStop(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := utillog.LoggerFromWriterWithMinLevelAndFormat(w, utillog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) utillog.SetupLogger(l, "debug") @@ -510,7 +509,7 @@ func Test_npCollectorImpl_ScheduleConns(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := utillog.LoggerFromWriterWithMinLevelAndFormat(w, utillog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) utillog.SetupLogger(l, "debug") @@ -564,7 +563,7 @@ func Test_npCollectorImpl_stopWorker(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := utillog.LoggerFromWriterWithMinLevelAndFormat(w, utillog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) utillog.SetupLogger(l, "debug") @@ -759,7 +758,7 @@ func Benchmark_npCollectorImpl_ScheduleConns(b *testing.B) { assert.Nil(b, err) defer file.Close() w := bufio.NewWriter(file) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg\n") + l, err := utillog.LoggerFromWriterWithMinLevelAndFormat(w, utillog.DebugLvl, "[%LEVEL] %FuncShort: %Msg\n") assert.Nil(b, err) utillog.SetupLogger(l, "debug") defer w.Flush() diff --git a/comp/networkpath/npcollector/npcollectorimpl/pathteststore/pathteststore_test.go b/comp/networkpath/npcollector/npcollectorimpl/pathteststore/pathteststore_test.go index a758c0664fa149..bf809bd31d9b6d 100644 --- a/comp/networkpath/npcollector/npcollectorimpl/pathteststore/pathteststore_test.go +++ b/comp/networkpath/npcollector/npcollectorimpl/pathteststore/pathteststore_test.go @@ -12,7 +12,6 @@ import ( "testing" "time" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" logmock "github.com/DataDog/datadog-agent/comp/core/log/mock" @@ -87,7 +86,7 @@ func Test_pathtestStore_add(t *testing.T) { t.Run(tc.name, func(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := utillog.LoggerFromWriterWithMinLevelAndFormat(w, utillog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) utillog.SetupLogger(l, "debug") diff --git a/comp/remote-config/rcclient/rcclientimpl/rcclient_test.go b/comp/remote-config/rcclient/rcclientimpl/rcclient_test.go index cf5a3cb0931396..f6974273d33255 100644 --- a/comp/remote-config/rcclient/rcclientimpl/rcclient_test.go +++ b/comp/remote-config/rcclient/rcclientimpl/rcclient_test.go @@ -25,7 +25,6 @@ import ( "github.com/DataDog/datadog-agent/pkg/util/fxutil" pkglog "github.com/DataDog/datadog-agent/pkg/util/log" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "go.uber.org/fx" ) @@ -96,7 +95,7 @@ func TestRCClientCreate(t *testing.T) { } func TestAgentConfigCallback(t *testing.T) { - pkglog.SetupLogger(seelog.Default, "info") + pkglog.SetupLogger(pkglog.Default(), "info") cfg := configmock.New(t) rc := fxutil.Test[rcclient.Component](t, diff --git a/comp/trace/config/config_test.go b/comp/trace/config/config_test.go index f428a7da51bc43..9c9d45eb284ac6 100644 --- a/comp/trace/config/config_test.go +++ b/comp/trace/config/config_test.go @@ -23,7 +23,6 @@ import ( "text/template" "time" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/fx" @@ -136,9 +135,8 @@ func TestSplitTagRegex(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - logger, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %Msg") + logger, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.DebugLvl, "[%LEVEL] %Msg") assert.Nil(t, err) - seelog.ReplaceLogger(logger) //nolint:errcheck log.SetupLogger(logger, "debug") assert.Nil(t, splitTagRegex(bad.tag)) w.Flush() diff --git a/pkg/clusteragent/api/leader_forwarder.go b/pkg/clusteragent/api/leader_forwarder.go index a5989f62d112b8..94d054d6508b50 100644 --- a/pkg/clusteragent/api/leader_forwarder.go +++ b/pkg/clusteragent/api/leader_forwarder.go @@ -18,8 +18,7 @@ import ( "sync" "time" - "github.com/cihub/seelog" - + "github.com/DataDog/datadog-agent/pkg/util/log" pkglogsetup "github.com/DataDog/datadog-agent/pkg/util/log/setup" ) @@ -43,7 +42,7 @@ type LeaderForwarder struct { // NewLeaderForwarder initializes a new LeaderForwarder instance and is used for test purposes func NewLeaderForwarder(apiPort, maxConnections int) *LeaderForwarder { // Use a stack depth of 4 on top of the default one to get a relevant filename in the stdlib - logWriter, _ := pkglogsetup.NewLogWriter(4, seelog.DebugLvl) + logWriter, _ := pkglogsetup.NewLogWriter(4, log.DebugLvl) return &LeaderForwarder{ apiPort: strconv.Itoa(apiPort), transport: &http.Transport{ diff --git a/pkg/collector/corechecks/ebpf/ebpf.go b/pkg/collector/corechecks/ebpf/ebpf.go index 934cb5bab4f12f..1638f60cef9d4a 100644 --- a/pkg/collector/corechecks/ebpf/ebpf.go +++ b/pkg/collector/corechecks/ebpf/ebpf.go @@ -13,7 +13,6 @@ import ( "net/http" "strings" - "github.com/cihub/seelog" "gopkg.in/yaml.v2" sysprobeclient "github.com/DataDog/datadog-agent/cmd/system-probe/api/client" @@ -152,7 +151,7 @@ func (m *EBPFCheck) Run() error { "module:" + progInfo.Module, } var debuglogs []string - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { debuglogs = []string{"program=" + progInfo.Name, "type=" + progInfo.Type.String()} } @@ -166,7 +165,7 @@ func (m *EBPFCheck) Run() error { continue } sender.Gauge("ebpf.programs."+k, v, "", tags) - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { debuglogs = append(debuglogs, fmt.Sprintf("%s=%.0f", k, v)) } } @@ -184,12 +183,12 @@ func (m *EBPFCheck) Run() error { continue } sender.MonotonicCountWithFlushFirstValue("ebpf.programs."+k, v, "", tags, true) - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { debuglogs = append(debuglogs, fmt.Sprintf("%s=%.0f", k, v)) } } - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("ebpf check: %s", strings.Join(debuglogs, " ")) } } diff --git a/pkg/collector/corechecks/ebpf/probe/ebpfcheck/probe.go b/pkg/collector/corechecks/ebpf/probe/ebpfcheck/probe.go index a25d5d49db2da5..d09baa968c0a59 100644 --- a/pkg/collector/corechecks/ebpf/probe/ebpfcheck/probe.go +++ b/pkg/collector/corechecks/ebpf/probe/ebpfcheck/probe.go @@ -20,7 +20,6 @@ import ( "unsafe" manager "github.com/DataDog/ebpf-manager" - "github.com/cihub/seelog" "github.com/cilium/ebpf" "github.com/cilium/ebpf/asm" "github.com/cilium/ebpf/features" @@ -318,7 +317,7 @@ func (k *Probe) getProgramStats(stats *model.EBPFStats) error { stats.Programs = append(stats.Programs, ps) } - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("found %d programs", len(stats.Programs)) for _, ps := range stats.Programs { log.Tracef("name=%s prog_id=%d type=%s", ps.Name, ps.ID, ps.Type.String()) diff --git a/pkg/collector/corechecks/snmp/internal/checkconfig/config.go b/pkg/collector/corechecks/snmp/internal/checkconfig/config.go index 1dc318f3848255..9084d26e664e71 100644 --- a/pkg/collector/corechecks/snmp/internal/checkconfig/config.go +++ b/pkg/collector/corechecks/snmp/internal/checkconfig/config.go @@ -17,7 +17,6 @@ import ( "strings" "time" - "github.com/cihub/seelog" "gopkg.in/yaml.v2" "github.com/DataDog/datadog-agent/comp/core/autodiscovery/integration" @@ -227,7 +226,7 @@ func (c *CheckConfig) SetProfile(profile string) error { c.ProfileDef = &definition c.Profile = profile - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { profileDefJSON, _ := json.Marshal(definition) log.Debugf("Profile content `%s`: %s", profile, string(profileDefJSON)) } diff --git a/pkg/collector/corechecks/snmp/internal/configvalidation/config_validate_enrich_test.go b/pkg/collector/corechecks/snmp/internal/configvalidation/config_validate_enrich_test.go index 0047af78cc366e..1682967a4c1b5a 100644 --- a/pkg/collector/corechecks/snmp/internal/configvalidation/config_validate_enrich_test.go +++ b/pkg/collector/corechecks/snmp/internal/configvalidation/config_validate_enrich_test.go @@ -13,7 +13,6 @@ import ( "strings" "testing" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "github.com/DataDog/datadog-agent/pkg/util/log" @@ -587,7 +586,7 @@ func Test_ValidateEnrichMetrics(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) log.SetupLogger(l, "debug") @@ -693,7 +692,7 @@ func Test_ValidateEnrichMetricTags(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) log.SetupLogger(l, "debug") diff --git a/pkg/collector/corechecks/snmp/internal/devicecheck/devicecheck.go b/pkg/collector/corechecks/snmp/internal/devicecheck/devicecheck.go index 8737e5845378f1..f63d0a4c33791f 100644 --- a/pkg/collector/corechecks/snmp/internal/devicecheck/devicecheck.go +++ b/pkg/collector/corechecks/snmp/internal/devicecheck/devicecheck.go @@ -15,7 +15,6 @@ import ( "strings" "time" - "github.com/cihub/seelog" "go.uber.org/atomic" "github.com/DataDog/datadog-agent/pkg/collector/externalhost" @@ -284,7 +283,7 @@ func (d *DeviceCheck) getValuesAndTags() (bool, []string, *valuestore.ResultValu checkErrors = append(checkErrors, fmt.Sprintf("check device reachable: failed: %s", err)) } else { deviceReachable = true - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { log.Debugf("check device reachable: success: %v", gosnmplib.PacketAsString(getNextValue)) } } @@ -298,7 +297,7 @@ func (d *DeviceCheck) getValuesAndTags() (bool, []string, *valuestore.ResultValu tags = append(tags, d.config.ProfileTags...) valuesStore, err := fetch.Fetch(d.session, d.config) - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { log.Debugf("fetched values: %v", valuestore.ResultValueStoreAsString(valuesStore)) } @@ -352,7 +351,7 @@ func (d *DeviceCheck) detectAvailableMetrics() ([]profiledefinition.MetricsConfi log.Debugf("fetched OIDs: %v", fetchedOIDs) root := common.BuildOidTrie(fetchedOIDs) - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { root.DebugPrint() } diff --git a/pkg/collector/corechecks/snmp/internal/fetch/fetch_column.go b/pkg/collector/corechecks/snmp/internal/fetch/fetch_column.go index 9d06254d861563..2ebfce8c4acd5b 100644 --- a/pkg/collector/corechecks/snmp/internal/fetch/fetch_column.go +++ b/pkg/collector/corechecks/snmp/internal/fetch/fetch_column.go @@ -9,7 +9,6 @@ import ( "fmt" "sort" - "github.com/cihub/seelog" "github.com/gosnmp/gosnmp" "github.com/DataDog/datadog-agent/pkg/util/log" @@ -105,7 +104,7 @@ func getResults(sess session.Session, requestOids []string, bulkMaxRepetitions u return nil, fmt.Errorf("fetch column: failed getting oids `%v` using GetNext: %s", requestOids, err) } results = getNextResults - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { log.Debugf("fetch column: GetNext results: %v", gosnmplib.PacketAsString(results)) } } else { @@ -115,7 +114,7 @@ func getResults(sess session.Session, requestOids []string, bulkMaxRepetitions u return nil, fmt.Errorf("fetch column: failed getting oids `%v` using GetBulk: %s", requestOids, err) } results = getBulkResults - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { log.Debugf("fetch column: GetBulk results: %v", gosnmplib.PacketAsString(results)) } } diff --git a/pkg/collector/corechecks/snmp/internal/fetch/fetch_scalar.go b/pkg/collector/corechecks/snmp/internal/fetch/fetch_scalar.go index 0fc948b17a061d..d7b219ad72c534 100644 --- a/pkg/collector/corechecks/snmp/internal/fetch/fetch_scalar.go +++ b/pkg/collector/corechecks/snmp/internal/fetch/fetch_scalar.go @@ -10,7 +10,6 @@ import ( "sort" "strings" - "github.com/cihub/seelog" "github.com/gosnmp/gosnmp" "github.com/DataDog/datadog-agent/pkg/util/log" @@ -127,7 +126,7 @@ func doDoFetchScalarOids(session session.Session, oids []string) (*gosnmp.SnmpPa log.Debugf("fetch scalar: error getting oids `%v`: %v", oids, err) return nil, fmt.Errorf("fetch scalar: error getting oids `%v`: %v", oids, err) } - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { log.Debugf("fetch scalar: results: %s", gosnmplib.PacketAsString(results)) } return results, nil diff --git a/pkg/collector/corechecks/snmp/internal/fetch/fetch_test.go b/pkg/collector/corechecks/snmp/internal/fetch/fetch_test.go index b615d40681dc07..c0bf331b2f7e55 100644 --- a/pkg/collector/corechecks/snmp/internal/fetch/fetch_test.go +++ b/pkg/collector/corechecks/snmp/internal/fetch/fetch_test.go @@ -12,7 +12,6 @@ import ( "strings" "testing" - "github.com/cihub/seelog" "github.com/gosnmp/gosnmp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -775,7 +774,7 @@ func Test_fetchValues_errors(t *testing.T) { func Test_fetchColumnOids_alreadyProcessed(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.DebugLvl, "[%LEVEL] %FuncShort: %Msg") require.NoError(t, err) log.SetupLogger(l, "debug") diff --git a/pkg/collector/corechecks/snmp/internal/profile/profile_resolver_test.go b/pkg/collector/corechecks/snmp/internal/profile/profile_resolver_test.go index d0e03a880b9287..1b744b66f38f41 100644 --- a/pkg/collector/corechecks/snmp/internal/profile/profile_resolver_test.go +++ b/pkg/collector/corechecks/snmp/internal/profile/profile_resolver_test.go @@ -13,7 +13,6 @@ import ( "strings" "testing" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -147,7 +146,7 @@ func Test_resolveProfiles(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) log.SetupLogger(l, "debug") diff --git a/pkg/collector/corechecks/snmp/internal/profile/profile_yaml_test.go b/pkg/collector/corechecks/snmp/internal/profile/profile_yaml_test.go index 81d7513ab9fa75..b617764b44cb26 100644 --- a/pkg/collector/corechecks/snmp/internal/profile/profile_yaml_test.go +++ b/pkg/collector/corechecks/snmp/internal/profile/profile_yaml_test.go @@ -13,13 +13,11 @@ import ( "strings" "testing" - "github.com/cihub/seelog" assert "github.com/stretchr/testify/require" pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" - "github.com/DataDog/datadog-agent/pkg/util/log" - "github.com/DataDog/datadog-agent/pkg/networkdevice/profile/profiledefinition" + "github.com/DataDog/datadog-agent/pkg/util/log" ) func getMetricFromProfile(p profiledefinition.ProfileDefinition, metricName string) *profiledefinition.MetricsConfig { @@ -124,7 +122,7 @@ func Test_loadYamlProfiles_invalidDir(t *testing.T) { func Test_loadYamlProfiles_invalidExtendProfile(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) log.SetupLogger(l, "debug") @@ -145,7 +143,7 @@ func Test_loadYamlProfiles_invalidExtendProfile(t *testing.T) { func Test_loadYamlProfiles_userAndDefaultProfileFolderDoesNotExist(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) log.SetupLogger(l, "debug") @@ -168,7 +166,7 @@ func Test_loadYamlProfiles_validAndInvalidProfiles(t *testing.T) { // Valid profiles should be returned even if some profiles are invalid var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) log.SetupLogger(l, "debug") diff --git a/pkg/collector/corechecks/snmp/internal/report/report_device_metadata_test.go b/pkg/collector/corechecks/snmp/internal/report/report_device_metadata_test.go index 92b745060bb59e..2cff0364b107f8 100644 --- a/pkg/collector/corechecks/snmp/internal/report/report_device_metadata_test.go +++ b/pkg/collector/corechecks/snmp/internal/report/report_device_metadata_test.go @@ -12,7 +12,6 @@ import ( "testing" "time" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -31,7 +30,7 @@ import ( func Test_metricSender_reportNetworkDeviceMetadata_withoutInterfaces(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.TraceLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.TraceLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) log.SetupLogger(l, "debug") diff --git a/pkg/collector/corechecks/snmp/internal/report/report_metrics_test.go b/pkg/collector/corechecks/snmp/internal/report/report_metrics_test.go index bf5ea9de7a72e8..8d11ffc5e08a48 100644 --- a/pkg/collector/corechecks/snmp/internal/report/report_metrics_test.go +++ b/pkg/collector/corechecks/snmp/internal/report/report_metrics_test.go @@ -11,7 +11,6 @@ import ( "strings" "testing" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" @@ -316,7 +315,7 @@ func TestSendMetric(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) log.SetupLogger(l, "debug") @@ -453,7 +452,7 @@ func Test_metricSender_reportMetrics(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) log.SetupLogger(l, "debug") @@ -640,7 +639,7 @@ func Test_metricSender_getCheckInstanceMetricTags(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) log.SetupLogger(l, "debug") diff --git a/pkg/collector/corechecks/snmp/internal/report/report_utils_test.go b/pkg/collector/corechecks/snmp/internal/report/report_utils_test.go index de9fefb1305810..6b530f3f7d7635 100644 --- a/pkg/collector/corechecks/snmp/internal/report/report_utils_test.go +++ b/pkg/collector/corechecks/snmp/internal/report/report_utils_test.go @@ -12,7 +12,6 @@ import ( "strings" "testing" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "gopkg.in/yaml.v2" @@ -772,7 +771,7 @@ metric_tags: var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) log.SetupLogger(l, "debug") @@ -1091,7 +1090,7 @@ func Test_getContantMetricValues(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) log.SetupLogger(l, "debug") diff --git a/pkg/collector/corechecks/snmp/internal/session/session.go b/pkg/collector/corechecks/snmp/internal/session/session.go index c39518d0a3f0a2..1d0995c1ed3c10 100644 --- a/pkg/collector/corechecks/snmp/internal/session/session.go +++ b/pkg/collector/corechecks/snmp/internal/session/session.go @@ -11,7 +11,6 @@ import ( "strings" "time" - "github.com/cihub/seelog" "github.com/gosnmp/gosnmp" "github.com/DataDog/datadog-agent/pkg/snmp/gosnmplib" @@ -137,7 +136,7 @@ func NewGosnmpSession(config *checkconfig.CheckConfig) (Session, error) { if err != nil { log.Warnf("failed to get logger: %s", err) } else { - if lvl == seelog.TraceLvl { + if lvl == log.TraceLvl { TraceLevelLogWriter := gosnmplib.TraceLevelLogWriter{} s.gosnmpInst.Logger = gosnmp.NewLogger(stdlog.New(&TraceLevelLogWriter, "", stdlog.Lshortfile)) } diff --git a/pkg/collector/corechecks/snmp/internal/session/session_test.go b/pkg/collector/corechecks/snmp/internal/session/session_test.go index 1042bc7b5de283..3986365f01e593 100644 --- a/pkg/collector/corechecks/snmp/internal/session/session_test.go +++ b/pkg/collector/corechecks/snmp/internal/session/session_test.go @@ -14,7 +14,6 @@ import ( "testing" "time" - "github.com/cihub/seelog" "github.com/gosnmp/gosnmp" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -289,7 +288,7 @@ func Test_snmpSession_traceLog_disabled(t *testing.T) { } var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.InfoLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.InfoLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) log.SetupLogger(l, "info") @@ -306,7 +305,7 @@ func Test_snmpSession_traceLog_enabled(t *testing.T) { } var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.TraceLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.TraceLvl, "[%LEVEL] %FuncShort: %Msg") assert.Nil(t, err) log.SetupLogger(l, "trace") diff --git a/pkg/collector/python/memory.go b/pkg/collector/python/memory.go index 38060ef37b462f..3d77d1bdd31bb4 100644 --- a/pkg/collector/python/memory.go +++ b/pkg/collector/python/memory.go @@ -14,8 +14,6 @@ import ( "sync" "unsafe" - "github.com/cihub/seelog" - pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" "github.com/DataDog/datadog-agent/pkg/telemetry" "github.com/DataDog/datadog-agent/pkg/util/log" @@ -76,7 +74,7 @@ func MemoryTracker(ptr unsafe.Pointer, sz C.size_t, op C.rtloader_mem_ops_t) { // but from profiling, even passing these vars through as arguments allocates to the heap. // This is an optimization to avoid even evaluating the `Tracef` call if the trace log // level is not enabled. - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("Memory Tracker - ptr: %v, sz: %v, op: %v", ptr, sz, op) } switch op { @@ -94,7 +92,7 @@ func MemoryTracker(ptr unsafe.Pointer, sz C.size_t, op C.rtloader_mem_ops_t) { if !ok { log.Debugf("untracked memory was attempted to be freed - set trace level for details") lvl, err := log.GetLogLevel() - if err == nil && lvl == seelog.TraceLvl { + if err == nil && lvl == log.TraceLvl { stack := string(debug.Stack()) log.Tracef("Memory Tracker - stacktrace: \n%s", stack) } diff --git a/pkg/ebpf/ebpftest/fail_log.go b/pkg/ebpf/ebpftest/fail_log.go index ccc8df5e112b45..15c98ef098188c 100644 --- a/pkg/ebpf/ebpftest/fail_log.go +++ b/pkg/ebpf/ebpftest/fail_log.go @@ -10,6 +10,7 @@ import ( "strings" "testing" + //nolint:depguard // creating a custom logger for testing "github.com/cihub/seelog" "github.com/DataDog/datadog-agent/pkg/util/log" @@ -21,7 +22,7 @@ func FailLogLevel(t testing.TB, level string) { inner := &failureTestLogger{TB: t} t.Cleanup(func() { t.Helper() - log.SetupLogger(seelog.Default, "off") + log.SetupLogger(log.Default(), "off") inner.outputIfFailed() }) logger, err := seelog.LoggerFromCustomReceiver(inner) diff --git a/pkg/ebpf/ebpftest/log.go b/pkg/ebpf/ebpftest/log.go index a13f7e14d9d346..06b1fb11fb7070 100644 --- a/pkg/ebpf/ebpftest/log.go +++ b/pkg/ebpf/ebpftest/log.go @@ -9,6 +9,7 @@ import ( "strings" "testing" + //nolint:depguard // creating a custom logger for testing "github.com/cihub/seelog" "github.com/DataDog/datadog-agent/pkg/util/log" @@ -17,7 +18,7 @@ import ( // LogLevel sets the logger level for this test only func LogLevel(t testing.TB, level string) { t.Cleanup(func() { - log.SetupLogger(seelog.Default, "off") + log.SetupLogger(log.Default(), "off") }) logger, err := seelog.LoggerFromCustomReceiver(testLogger{t}) if err != nil { diff --git a/pkg/ebpf/map_cleaner_test.go b/pkg/ebpf/map_cleaner_test.go index 635c882a36bedb..a9dfdbd1cb32bd 100644 --- a/pkg/ebpf/map_cleaner_test.go +++ b/pkg/ebpf/map_cleaner_test.go @@ -12,7 +12,6 @@ import ( "testing" "time" - "github.com/cihub/seelog" "github.com/cilium/ebpf" "github.com/cilium/ebpf/rlimit" "github.com/stretchr/testify/assert" @@ -26,7 +25,7 @@ func TestMain(m *testing.M) { if logLevel == "" { logLevel = "warn" } - log.SetupLogger(seelog.Default, logLevel) + log.SetupLogger(log.Default(), logLevel) os.Exit(m.Run()) } diff --git a/pkg/ebpf/verifier/stats_test.go b/pkg/ebpf/verifier/stats_test.go index 9af6a7c3f4cc2e..fca00b8840f165 100644 --- a/pkg/ebpf/verifier/stats_test.go +++ b/pkg/ebpf/verifier/stats_test.go @@ -19,7 +19,6 @@ import ( "github.com/DataDog/datadog-agent/pkg/util/kernel" "github.com/DataDog/datadog-agent/pkg/util/log" - "github.com/cihub/seelog" "github.com/cilium/ebpf" "github.com/cilium/ebpf/rlimit" "github.com/stretchr/testify/assert" @@ -37,7 +36,7 @@ func TestMain(m *testing.M) { if logLevel == "" { logLevel = "warn" } - log.SetupLogger(seelog.Default, logLevel) + log.SetupLogger(log.Default(), logLevel) os.Exit(m.Run()) } diff --git a/pkg/gohai/cpu/util_linux.go b/pkg/gohai/cpu/util_linux.go index 129801f8bdaf2c..fc82760141e568 100644 --- a/pkg/gohai/cpu/util_linux.go +++ b/pkg/gohai/cpu/util_linux.go @@ -12,7 +12,7 @@ import ( "strconv" "strings" - log "github.com/cihub/seelog" + "github.com/DataDog/datadog-agent/pkg/util/log" ) var prefix = "" // only used for testing diff --git a/pkg/gohai/filesystem/filesystem_nix.go b/pkg/gohai/filesystem/filesystem_nix.go index 27f5094d1e2821..f4171904f60bd8 100644 --- a/pkg/gohai/filesystem/filesystem_nix.go +++ b/pkg/gohai/filesystem/filesystem_nix.go @@ -10,10 +10,10 @@ import ( "fmt" "strings" + "github.com/moby/sys/mountinfo" "golang.org/x/sys/unix" - log "github.com/cihub/seelog" - "github.com/moby/sys/mountinfo" + "github.com/DataDog/datadog-agent/pkg/util/log" ) type fsInfoGetter func(*mountinfo.Info) (uint64, error) diff --git a/pkg/gohai/go.mod b/pkg/gohai/go.mod index d836c017c69c61..c01af5d3997284 100644 --- a/pkg/gohai/go.mod +++ b/pkg/gohai/go.mod @@ -6,7 +6,6 @@ go 1.23.0 require ( github.com/DataDog/datadog-agent/pkg/util/log v0.56.0-rc.3 - github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 github.com/moby/sys/mountinfo v0.7.2 github.com/shirou/gopsutil/v3 v3.24.5 github.com/stretchr/testify v1.10.0 @@ -15,6 +14,7 @@ require ( require ( github.com/DataDog/datadog-agent/pkg/util/scrubber v0.56.0-rc.3 // indirect + github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/go-ole/go-ole v1.3.0 // indirect github.com/kr/text v0.2.0 // indirect diff --git a/pkg/gohai/memory/memory_linux.go b/pkg/gohai/memory/memory_linux.go index 356d9dee67d9e5..822a082fc4aee7 100644 --- a/pkg/gohai/memory/memory_linux.go +++ b/pkg/gohai/memory/memory_linux.go @@ -14,7 +14,7 @@ import ( "strings" "github.com/DataDog/datadog-agent/pkg/gohai/utils" - log "github.com/cihub/seelog" + "github.com/DataDog/datadog-agent/pkg/util/log" ) func parseMemoryInfo(reader io.Reader) (totalBytes utils.Value[uint64], swapTotalKb utils.Value[uint64], err error) { diff --git a/pkg/gohai/platform/platform_darwin.go b/pkg/gohai/platform/platform_darwin.go index e1fb7ed154923e..a28bdf3ebead59 100644 --- a/pkg/gohai/platform/platform_darwin.go +++ b/pkg/gohai/platform/platform_darwin.go @@ -9,9 +9,10 @@ import ( "errors" "runtime" - "github.com/DataDog/datadog-agent/pkg/gohai/utils" - log "github.com/cihub/seelog" "golang.org/x/sys/unix" + + "github.com/DataDog/datadog-agent/pkg/gohai/utils" + "github.com/DataDog/datadog-agent/pkg/util/log" ) // getUnameProcessor is similar to `uname -p` diff --git a/pkg/gohai/processes/gops/process_info.go b/pkg/gohai/processes/gops/process_info.go index 8f21f07ba5dc8b..9f830d935ea477 100644 --- a/pkg/gohai/processes/gops/process_info.go +++ b/pkg/gohai/processes/gops/process_info.go @@ -12,12 +12,10 @@ import ( "fmt" "runtime" - // 3p - log "github.com/cihub/seelog" - - // project "github.com/shirou/gopsutil/v3/mem" "github.com/shirou/gopsutil/v3/process" + + "github.com/DataDog/datadog-agent/pkg/util/log" ) // ProcessInfo contains information about a single process diff --git a/pkg/logs/tailers/windowsevent/tailer_test.go b/pkg/logs/tailers/windowsevent/tailer_test.go index 5c8c635314edbb..8fb0c2311d49a3 100644 --- a/pkg/logs/tailers/windowsevent/tailer_test.go +++ b/pkg/logs/tailers/windowsevent/tailer_test.go @@ -13,8 +13,6 @@ import ( "testing" "time" - "github.com/cihub/seelog" - pkglog "github.com/DataDog/datadog-agent/pkg/util/log" "github.com/cenkalti/backoff" @@ -61,7 +59,7 @@ func TestReadEventsSuite(t *testing.T) { func (s *ReadEventsSuite) SetupSuite() { // Enable logger if false { - pkglog.SetupLogger(seelog.Default, "debug") + pkglog.SetupLogger(pkglog.Default(), "debug") } s.ti = eventlog_test.GetAPITesterByName(s.testAPI, s.T()) diff --git a/pkg/network/encoding/marshal/usm.go b/pkg/network/encoding/marshal/usm.go index bcae7a12ecc121..437a0ba4b0d649 100644 --- a/pkg/network/encoding/marshal/usm.go +++ b/pkg/network/encoding/marshal/usm.go @@ -9,8 +9,6 @@ import ( "fmt" "sync" - "github.com/cihub/seelog" - pkgconfigsetup "github.com/DataDog/datadog-agent/pkg/config/setup" "github.com/DataDog/datadog-agent/pkg/network" "github.com/DataDog/datadog-agent/pkg/network/protocols/telemetry" @@ -192,7 +190,7 @@ func (bc *USMConnectionIndex[K, V]) Close() { var total int for key, value := range bc.data { if !value.claimed { - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("key %+v unclaimed", key) } total += len(value.Data) diff --git a/pkg/network/go/bininspect/symbols.go b/pkg/network/go/bininspect/symbols.go index 6b5f135179fe15..8549fde56f4066 100644 --- a/pkg/network/go/bininspect/symbols.go +++ b/pkg/network/go/bininspect/symbols.go @@ -14,8 +14,6 @@ import ( "io" "math" - "github.com/cihub/seelog" - "github.com/DataDog/datadog-agent/pkg/util/common" "github.com/DataDog/datadog-agent/pkg/util/log" "github.com/DataDog/datadog-agent/pkg/util/safeelf" @@ -222,7 +220,7 @@ func getSymbols(f *safeelf.File, typ safeelf.SectionType, filter symbolFilter) ( // returned. func GetAllSymbolsByName(elfFile *safeelf.File, filter symbolFilter) (map[string]safeelf.Symbol, error) { regularSymbols, regularSymbolsErr := getSymbols(elfFile, safeelf.SHT_SYMTAB, filter) - if regularSymbolsErr != nil && log.ShouldLog(seelog.TraceLvl) { + if regularSymbolsErr != nil && log.ShouldLog(log.TraceLvl) { log.Tracef("Failed getting regular symbols of elf file: %s", regularSymbolsErr) } @@ -231,7 +229,7 @@ func GetAllSymbolsByName(elfFile *safeelf.File, filter symbolFilter) (map[string numWanted := filter.getNumWanted() if len(regularSymbols) != numWanted { dynamicSymbols, dynamicSymbolsErr = getSymbols(elfFile, safeelf.SHT_DYNSYM, filter) - if dynamicSymbolsErr != nil && log.ShouldLog(seelog.TraceLvl) { + if dynamicSymbolsErr != nil && log.ShouldLog(log.TraceLvl) { log.Tracef("Failed getting dynamic symbols of elf file: %s", dynamicSymbolsErr) } } diff --git a/pkg/network/netlink/conntrack_integration_test.go b/pkg/network/netlink/conntrack_integration_test.go index 2788153c3f3256..46049481e9945b 100644 --- a/pkg/network/netlink/conntrack_integration_test.go +++ b/pkg/network/netlink/conntrack_integration_test.go @@ -13,7 +13,6 @@ import ( "os" "testing" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -31,7 +30,7 @@ func TestMain(m *testing.M) { if logLevel == "" { logLevel = "warn" } - log.SetupLogger(seelog.Default, logLevel) + log.SetupLogger(log.Default(), logLevel) os.Exit(m.Run()) } diff --git a/pkg/network/netlink/conntracker.go b/pkg/network/netlink/conntracker.go index 901e763bf2e4b4..16e9ff3a4f8c6a 100644 --- a/pkg/network/netlink/conntracker.go +++ b/pkg/network/netlink/conntracker.go @@ -20,7 +20,6 @@ import ( "github.com/syndtr/gocapability/capability" "golang.org/x/sys/unix" - "github.com/cihub/seelog" "github.com/hashicorp/golang-lru/v2/simplelru" telemetryComp "github.com/DataDog/datadog-agent/comp/core/telemetry" @@ -411,7 +410,7 @@ func (cc *conntrackCache) Add(c Con, orphan bool) (evicts int) { } } - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("%s", c) } @@ -433,7 +432,7 @@ func (cc *conntrackCache) removeOrphans(now time.Time) (removed int64) { cc.cache.Remove(o.key) removed++ - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("removed orphan %+v", o.key) } } diff --git a/pkg/network/netlink/consumer.go b/pkg/network/netlink/consumer.go index ff3d2950e809dc..c912db22715e51 100644 --- a/pkg/network/netlink/consumer.go +++ b/pkg/network/netlink/consumer.go @@ -13,7 +13,6 @@ import ( "strings" "syscall" - "github.com/cihub/seelog" "github.com/mdlayher/netlink" "github.com/pkg/errors" "github.com/vishvananda/netns" @@ -205,7 +204,7 @@ func (c *Consumer) isPeerNS(conn *netlink.Conn, ns netns.NsHandle) bool { return false } - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("netlink reply: %v", msgs) } diff --git a/pkg/network/port_test.go b/pkg/network/port_test.go index 995a4e8ef0a2f9..067417ae79d484 100644 --- a/pkg/network/port_test.go +++ b/pkg/network/port_test.go @@ -17,7 +17,6 @@ import ( "strconv" "testing" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/vishvananda/netns" @@ -32,7 +31,7 @@ func TestMain(m *testing.M) { if logLevel == "" { logLevel = "warn" } - log.SetupLogger(seelog.Default, logLevel) + log.SetupLogger(log.Default(), logLevel) os.Exit(m.Run()) } diff --git a/pkg/network/protocols/events/consumer.go b/pkg/network/protocols/events/consumer.go index dea561ee8297fe..eb00d29678b656 100644 --- a/pkg/network/protocols/events/consumer.go +++ b/pkg/network/protocols/events/consumer.go @@ -13,8 +13,6 @@ import ( "sync" "unsafe" - "github.com/cihub/seelog" - manager "github.com/DataDog/ebpf-manager" ddebpf "github.com/DataDog/datadog-agent/pkg/ebpf" @@ -169,7 +167,7 @@ func (c *Consumer[V]) Start() { c.batchReader.ReadAll(func(_ int, b *batch) { c.process(b, true) }) - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { log.Debugf("usm events summary: name=%q %s", c.proto, c.metricGroup.Summary()) } close(done) diff --git a/pkg/network/protocols/http/telemetry.go b/pkg/network/protocols/http/telemetry.go index 0dddb2591fee9e..2d73136b7417b5 100644 --- a/pkg/network/protocols/http/telemetry.go +++ b/pkg/network/protocols/http/telemetry.go @@ -10,8 +10,6 @@ package http import ( "fmt" - "github.com/cihub/seelog" - libtelemetry "github.com/DataDog/datadog-agent/pkg/network/protocols/telemetry" "github.com/DataDog/datadog-agent/pkg/util/log" ) @@ -99,7 +97,7 @@ func (t *Telemetry) Count(tx Transaction) { // Log logs the telemetry. func (t *Telemetry) Log() { - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { log.Debugf("%s stats summary: %s", t.protocol, t.metricGroup.Summary()) } } diff --git a/pkg/network/protocols/http2/telemetry.go b/pkg/network/protocols/http2/telemetry.go index e80b5efd1a8982..6e74ad3e7ba07c 100644 --- a/pkg/network/protocols/http2/telemetry.go +++ b/pkg/network/protocols/http2/telemetry.go @@ -10,8 +10,6 @@ package http2 import ( "strconv" - "github.com/cihub/seelog" - libtelemetry "github.com/DataDog/datadog-agent/pkg/network/protocols/telemetry" "github.com/DataDog/datadog-agent/pkg/util/log" ) @@ -91,7 +89,7 @@ func (t *kernelTelemetry) update(tel *HTTP2Telemetry, isTLS bool) { } func (t *kernelTelemetry) Log() { - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { log.Debugf("http2 kernel telemetry summary: %s", t.metricGroup.Summary()) } } diff --git a/pkg/network/protocols/kafka/telemetry.go b/pkg/network/protocols/kafka/telemetry.go index 9905756dd880e8..cb91b714f09844 100644 --- a/pkg/network/protocols/kafka/telemetry.go +++ b/pkg/network/protocols/kafka/telemetry.go @@ -8,8 +8,6 @@ package kafka import ( - "github.com/cihub/seelog" - libtelemetry "github.com/DataDog/datadog-agent/pkg/network/protocols/telemetry" "github.com/DataDog/datadog-agent/pkg/util/log" ) @@ -51,7 +49,7 @@ func (t *Telemetry) Count(tx *KafkaTransaction) { // Log logs the kafka stats summary func (t *Telemetry) Log() { - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { log.Debugf("kafka stats summary: %s", t.metricGroup.Summary()) } } diff --git a/pkg/network/protocols/postgres/telemetry.go b/pkg/network/protocols/postgres/telemetry.go index cc17b902c24eac..2b84118dd35cce 100644 --- a/pkg/network/protocols/postgres/telemetry.go +++ b/pkg/network/protocols/postgres/telemetry.go @@ -10,8 +10,6 @@ package postgres import ( "fmt" - "github.com/cihub/seelog" - "github.com/DataDog/datadog-agent/pkg/network/config" "github.com/DataDog/datadog-agent/pkg/network/protocols/postgres/ebpf" libtelemetry "github.com/DataDog/datadog-agent/pkg/network/protocols/telemetry" @@ -174,7 +172,7 @@ func (t *Telemetry) Count(tx *ebpf.EbpfEvent, eventWrapper *EventWrapper) { // Log logs the postgres stats summary func (t *Telemetry) Log() { - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { log.Debugf("postgres stats summary: %s", t.metricGroup.Summary()) } } diff --git a/pkg/network/state.go b/pkg/network/state.go index 155e75e78ca075..39094959989acc 100644 --- a/pkg/network/state.go +++ b/pkg/network/state.go @@ -11,7 +11,6 @@ import ( "sync" "time" - "github.com/cihub/seelog" "go4.org/intern" telemetryComponent "github.com/DataDog/datadog-agent/comp/core/telemetry" @@ -565,7 +564,7 @@ func (ns *networkState) mergeByCookie(conns []ConnectionStats) ([]ConnectionStat return true } - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("duplicate connection in collection: cookie: %d, c1: %+v, c2: %+v", c.Cookie, *ck, *c) } diff --git a/pkg/network/tracer/connection/ebpf_tracer.go b/pkg/network/tracer/connection/ebpf_tracer.go index ba58ada66b19ca..d181471578d216 100644 --- a/pkg/network/tracer/connection/ebpf_tracer.go +++ b/pkg/network/tracer/connection/ebpf_tracer.go @@ -17,7 +17,6 @@ import ( manager "github.com/DataDog/ebpf-manager" "github.com/DataDog/ebpf-manager/tracefs" - "github.com/cihub/seelog" "github.com/cilium/ebpf" "github.com/prometheus/client_golang/prometheus" "go.uber.org/atomic" @@ -501,7 +500,7 @@ func (t *ebpfTracer) getEBPFTelemetry() *netebpf.Telemetry { if err := mp.Lookup(&zero, tm); err != nil { // This can happen if we haven't initialized the telemetry object yet // so let's just use a trace log - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("error retrieving the telemetry struct: %s", err) } return nil diff --git a/pkg/network/tracer/ebpf_conntracker.go b/pkg/network/tracer/ebpf_conntracker.go index 89c34dca9578bb..873ee9d4530054 100644 --- a/pkg/network/tracer/ebpf_conntracker.go +++ b/pkg/network/tracer/ebpf_conntracker.go @@ -16,7 +16,6 @@ import ( "time" manager "github.com/DataDog/ebpf-manager" - "github.com/cihub/seelog" "github.com/cilium/ebpf" "github.com/cilium/ebpf/features" "github.com/prometheus/client_golang/prometheus" @@ -239,7 +238,7 @@ func (e *ebpfConntracker) GetTranslationForConn(stats *network.ConnectionTuple) defer tuplePool.Put(src) toConntrackTupleFromTuple(src, stats) - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("looking up in conntrack (stats): %s", stats) } @@ -247,14 +246,14 @@ func (e *ebpfConntracker) GetTranslationForConn(stats *network.ConnectionTuple) // NAT rules referencing conntrack are installed there instead // of other network namespaces (for pods, for instance) src.Netns = e.rootNS - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("looking up in conntrack (tuple): %s", src) } dst := e.get(src) if dst == nil && stats.NetNS != e.rootNS { // Perform another lookup, this time using the connection namespace src.Netns = stats.NetNS - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("looking up in conntrack (tuple,netns): %s", src) } dst = e.get(src) @@ -299,7 +298,7 @@ func (e *ebpfConntracker) delete(key *netebpf.ConntrackTuple) { if err := e.ctMap.Delete(key); err != nil { if errors.Is(err, ebpf.ErrKeyNotExist) { - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("connection does not exist in ebpf conntrack map: %s", key) } diff --git a/pkg/network/tracer/process_cache.go b/pkg/network/tracer/process_cache.go index b44eb56f044cc6..acfb96bbde0f24 100644 --- a/pkg/network/tracer/process_cache.go +++ b/pkg/network/tracer/process_cache.go @@ -12,7 +12,6 @@ import ( "sync" "time" - "github.com/cihub/seelog" lru "github.com/hashicorp/golang-lru/v2" "github.com/prometheus/client_golang/prometheus" @@ -175,7 +174,7 @@ func (pc *processCache) add(p *events.Process) { pc.mu.Lock() defer pc.mu.Unlock() - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("adding process %+v to process cache", p) } p.Expiry = time.Now().Add(defaultExpiry).Unix() diff --git a/pkg/network/tracer/tracer.go b/pkg/network/tracer/tracer.go index 20e97a49ac3e6d..56eaf657a802ff 100644 --- a/pkg/network/tracer/tracer.go +++ b/pkg/network/tracer/tracer.go @@ -16,7 +16,6 @@ import ( "sync" "time" - "github.com/cihub/seelog" "github.com/cilium/ebpf" "go.uber.org/atomic" "go4.org/intern" @@ -346,7 +345,7 @@ func (t *Tracer) addProcessInfo(c *network.ConnectionStats) { return } - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("got process cache entry for pid %d: %+v", c.Pid, p) } @@ -413,7 +412,7 @@ func (t *Tracer) Stop() { func (t *Tracer) GetActiveConnections(clientID string) (*network.Connections, error) { t.bufferLock.Lock() defer t.bufferLock.Unlock() - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("GetActiveConnections clientID=%s", clientID) } t.ebpfTracer.FlushPending() @@ -611,7 +610,7 @@ func (t *Tracer) removeEntries(entries []network.ConnectionStats) { t.state.RemoveConnections(toRemove) - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { log.Debugf("Removed %d connection entries in %s", len(toRemove), time.Since(now)) } } diff --git a/pkg/network/tracer/tracer_test.go b/pkg/network/tracer/tracer_test.go index b032aabe44c5fe..ab364e2cefce91 100644 --- a/pkg/network/tracer/tracer_test.go +++ b/pkg/network/tracer/tracer_test.go @@ -26,7 +26,6 @@ import ( "testing" "time" - "github.com/cihub/seelog" "github.com/miekg/dns" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -55,7 +54,7 @@ func TestMain(m *testing.M) { if logLevel == "" { logLevel = "warn" } - log.SetupLogger(seelog.Default, logLevel) + log.SetupLogger(log.Default(), logLevel) platformInit() os.Exit(m.Run()) } diff --git a/pkg/network/usm/ebpf_gotls.go b/pkg/network/usm/ebpf_gotls.go index e12871aa619bfb..2c1e31300612af 100644 --- a/pkg/network/usm/ebpf_gotls.go +++ b/pkg/network/usm/ebpf_gotls.go @@ -19,7 +19,6 @@ import ( "time" "unsafe" - "github.com/cihub/seelog" "github.com/cilium/ebpf" "golang.org/x/sys/unix" @@ -355,7 +354,7 @@ func (p *goTLSProgram) AttachPID(pid uint32) error { // Check if the process is datadog's internal process, if so, we don't want to hook the process. if internalProcessRegex.MatchString(binPath) { - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { log.Debugf("ignoring pid %d, as it is an internal datadog component (%q)", pid, binPath) } return ErrInternalDDogProcessRejected diff --git a/pkg/network/usm/monitor_test.go b/pkg/network/usm/monitor_test.go index 402243c2562d1d..f899eb6c295b91 100644 --- a/pkg/network/usm/monitor_test.go +++ b/pkg/network/usm/monitor_test.go @@ -24,7 +24,6 @@ import ( "time" manager "github.com/DataDog/ebpf-manager" - "github.com/cihub/seelog" "github.com/cilium/ebpf" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -49,7 +48,7 @@ func TestMain(m *testing.M) { if logLevel == "" { logLevel = "warn" } - log.SetupLogger(seelog.Default, logLevel) + log.SetupLogger(log.Default(), logLevel) os.Exit(m.Run()) } diff --git a/pkg/network/usm/tests/tracer_classification_test.go b/pkg/network/usm/tests/tracer_classification_test.go index fb167ab7e093ca..1ddaa35bed5a53 100644 --- a/pkg/network/usm/tests/tracer_classification_test.go +++ b/pkg/network/usm/tests/tracer_classification_test.go @@ -20,7 +20,6 @@ import ( "testing" "time" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -44,7 +43,7 @@ func TestMain(m *testing.M) { if logLevel == "" { logLevel = "warn" } - log.SetupLogger(seelog.Default, logLevel) + log.SetupLogger(log.Default(), logLevel) platformInit() os.Exit(m.Run()) } diff --git a/pkg/network/usm/utils/file_registry.go b/pkg/network/usm/utils/file_registry.go index 177a4ac7c5857e..851d816618e860 100644 --- a/pkg/network/usm/utils/file_registry.go +++ b/pkg/network/usm/utils/file_registry.go @@ -13,7 +13,6 @@ import ( "os" "sync" - "github.com/cihub/seelog" "github.com/hashicorp/golang-lru/v2/simplelru" "go.uber.org/atomic" @@ -263,7 +262,7 @@ func (r *FileRegistry) GetRegisteredProcesses() map[uint32]struct{} { // Log state of `FileRegistry` func (r *FileRegistry) Log() { - if log.ShouldLog(seelog.DebugLvl) { + if log.ShouldLog(log.DebugLvl) { log.Debugf("file_registry summary: program=%s %s", r.telemetry.programName, r.telemetry.metricGroup.Summary()) } } diff --git a/pkg/process/metadata/parser/service.go b/pkg/process/metadata/parser/service.go index a2ef465a410a79..bacff8563b51ce 100644 --- a/pkg/process/metadata/parser/service.go +++ b/pkg/process/metadata/parser/service.go @@ -14,7 +14,6 @@ import ( "unicode" "github.com/Masterminds/semver" - "github.com/cihub/seelog" "github.com/DataDog/datadog-agent/pkg/process/metadata" javaparser "github.com/DataDog/datadog-agent/pkg/process/metadata/parser/java" @@ -109,7 +108,7 @@ func (d *ServiceExtractor) Extract(processes map[int32]*procutil.Process) { } } meta := d.extractServiceMetadata(proc) - if meta != nil && log.ShouldLog(seelog.TraceLvl) { + if meta != nil && log.ShouldLog(log.TraceLvl) { log.Tracef("detected service metadata: %v", meta) } serviceByPID[proc.Pid] = meta @@ -132,7 +131,7 @@ func (d *ServiceExtractor) GetServiceContext(pid int32) []string { // Service tag was found from the SCM, return it. if len(tags) > 0 { - if log.ShouldLog(seelog.TraceLvl) { + if log.ShouldLog(log.TraceLvl) { log.Tracef("Found process_context from SCM for pid:%v service tags:%v", pid, tags) } return tags diff --git a/pkg/process/monitor/process_monitor.go b/pkg/process/monitor/process_monitor.go index 1b9e30eb1ec849..0cb5b96adc0060 100644 --- a/pkg/process/monitor/process_monitor.go +++ b/pkg/process/monitor/process_monitor.go @@ -14,7 +14,6 @@ import ( "sync" "time" - "github.com/cihub/seelog" "github.com/vishvananda/netlink" "go.uber.org/atomic" @@ -177,7 +176,7 @@ func (pm *ProcessMonitor) handleProcessExec(pid uint32) { continue default: pm.tel.processExecChannelIsFull.Add(1) - if log.ShouldLog(seelog.DebugLvl) && pm.oversizedLogLimit.ShouldLog() { + if log.ShouldLog(log.DebugLvl) && pm.oversizedLogLimit.ShouldLog() { log.Debug("can't send exec callback to callbackRunner, channel is full") } } @@ -197,7 +196,7 @@ func (pm *ProcessMonitor) handleProcessExit(pid uint32) { continue default: pm.tel.processExitChannelIsFull.Add(1) - if log.ShouldLog(seelog.DebugLvl) && pm.oversizedLogLimit.ShouldLog() { + if log.ShouldLog(log.DebugLvl) && pm.oversizedLogLimit.ShouldLog() { log.Debug("can't send exit callback to callbackRunner, channel is full") } } diff --git a/pkg/process/procutil/process_linux_test.go b/pkg/process/procutil/process_linux_test.go index 7684ed119720ea..ac6a58d0e7e9c5 100644 --- a/pkg/process/procutil/process_linux_test.go +++ b/pkg/process/procutil/process_linux_test.go @@ -16,6 +16,7 @@ import ( "testing" "time" + // nolint:depguard // disable logs from DataDog/gopsutil "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/pkg/security/seclog/logger.go b/pkg/security/seclog/logger.go index 632c9efde74988..c6f2aff1a24f7c 100644 --- a/pkg/security/seclog/logger.go +++ b/pkg/security/seclog/logger.go @@ -13,8 +13,6 @@ import ( "strings" "sync" - "github.com/cihub/seelog" - "github.com/DataDog/datadog-agent/pkg/util/log" ) @@ -138,7 +136,7 @@ func (l *PatternLogger) Tracef(format string, params ...interface{}) { // IsTracing is used to check if TraceF would actually log func (l *PatternLogger) IsTracing() bool { - if logLevel, err := log.GetLogLevel(); err != nil || logLevel != seelog.TraceLvl { + if logLevel, err := log.GetLogLevel(); err != nil || logLevel != log.TraceLvl { return false } return true diff --git a/pkg/security/tests/main_test.go b/pkg/security/tests/main_test.go index 6ef5e6cdb8a80e..36b434722dc9df 100644 --- a/pkg/security/tests/main_test.go +++ b/pkg/security/tests/main_test.go @@ -15,7 +15,7 @@ import ( "testing" "time" - "github.com/cihub/seelog" + "github.com/DataDog/datadog-agent/pkg/util/log" ) // TestMain is the entry points for functional tests @@ -43,7 +43,7 @@ var ( ) func init() { - flag.StringVar(&logLevelStr, "loglevel", seelog.WarnStr, "log level") + flag.StringVar(&logLevelStr, "loglevel", log.WarnStr, "log level") flag.Var(&logPatterns, "logpattern", "List of log pattern") flag.Var(&logTags, "logtag", "List of log tag") diff --git a/pkg/security/tests/module_tester_linux.go b/pkg/security/tests/module_tester_linux.go index 268fc839f625ed..54d262fdf599d8 100644 --- a/pkg/security/tests/module_tester_linux.go +++ b/pkg/security/tests/module_tester_linux.go @@ -27,7 +27,6 @@ import ( "time" "github.com/avast/retry-go/v4" - "github.com/cihub/seelog" "github.com/davecgh/go-spew/spew" "github.com/hashicorp/go-multierror" "github.com/oliveagle/jsonpath" @@ -57,7 +56,7 @@ import ( ) var ( - logger seelog.LoggerInterface + logger log.LoggerInterface ) const ( @@ -999,7 +998,7 @@ func (tm *testModule) Close() { var logInitilialized bool func initLogger() error { - logLevel, found := seelog.LogLevelFromString(logLevelStr) + logLevel, found := log.LogLevelFromString(logLevelStr) if !found { return fmt.Errorf("invalid log level '%s'", logLevel) } @@ -1014,20 +1013,20 @@ func initLogger() error { return nil } -func swapLogLevel(logLevel seelog.LogLevel) (seelog.LogLevel, error) { +func swapLogLevel(logLevel log.LogLevel) (log.LogLevel, error) { if logger == nil { logFormat := "[%Date(2006-01-02 15:04:05.000)] [%LEVEL] %Func:%Line %Msg\n" var err error - logger, err = seelog.LoggerFromWriterWithMinLevelAndFormat(os.Stdout, logLevel, logFormat) + logger, err = log.LoggerFromWriterWithMinLevelAndFormat(os.Stdout, logLevel, logFormat) if err != nil { return 0, err } } log.SetupLogger(logger, logLevel.String()) - prevLevel, _ := seelog.LogLevelFromString(logLevelStr) + prevLevel, _ := log.LogLevelFromString(logLevelStr) logLevelStr = logLevel.String() return prevLevel, nil } diff --git a/pkg/serverless/daemon/routes_test.go b/pkg/serverless/daemon/routes_test.go index e0f2fea43a6374..25231204af6c8d 100644 --- a/pkg/serverless/daemon/routes_test.go +++ b/pkg/serverless/daemon/routes_test.go @@ -17,7 +17,6 @@ import ( "testing" "time" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" nooptagger "github.com/DataDog/datadog-agent/comp/core/tagger/impl-noop" @@ -399,7 +398,7 @@ func getEventFromFile(filename string) string { func BenchmarkStartEndInvocation(b *testing.B) { // Set the logger up, so that it does not buffer all entries forever (some of these are BIG as they include the // JSON payload). We're not interested in any output here, so we send it all to `io.Discard`. - l, err := seelog.LoggerFromWriterWithMinLevel(io.Discard, seelog.ErrorLvl) + l, err := log.LoggerFromWriterWithMinLevel(io.Discard, log.ErrorLvl) assert.Nil(b, err) log.SetupLogger(l, "error") diff --git a/pkg/snmp/gosnmplib/gosnmp_log_test.go b/pkg/snmp/gosnmplib/gosnmp_log_test.go index 264c81142d4276..30394a680cc135 100644 --- a/pkg/snmp/gosnmplib/gosnmp_log_test.go +++ b/pkg/snmp/gosnmplib/gosnmp_log_test.go @@ -10,7 +10,6 @@ import ( "bytes" "testing" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -92,7 +91,7 @@ func TestTraceLevelLogWriter_Write(t *testing.T) { t.Run(tt.name, func(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.TraceLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := log.LoggerFromWriterWithMinLevelAndFormat(w, log.TraceLvl, "[%LEVEL] %FuncShort: %Msg") require.NoError(t, err) log.SetupLogger(l, "trace") diff --git a/pkg/trace/go.mod b/pkg/trace/go.mod index bd0db6ed04e59c..22bcede92d68fd 100644 --- a/pkg/trace/go.mod +++ b/pkg/trace/go.mod @@ -24,7 +24,7 @@ require ( github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes v0.21.0 github.com/DataDog/sketches-go v1.4.6 github.com/Microsoft/go-winio v0.6.2 - github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 + github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.4 diff --git a/pkg/trace/remoteconfighandler/remote_config_handler.go b/pkg/trace/remoteconfighandler/remote_config_handler.go index a1d24e7b8e744b..0aff0f665099e5 100644 --- a/pkg/trace/remoteconfighandler/remote_config_handler.go +++ b/pkg/trace/remoteconfighandler/remote_config_handler.go @@ -19,7 +19,6 @@ import ( "github.com/DataDog/datadog-agent/pkg/trace/log" pkglog "github.com/DataDog/datadog-agent/pkg/util/log" - "github.com/cihub/seelog" "github.com/davecgh/go-spew/spew" ) @@ -95,7 +94,7 @@ func (h *RemoteConfigHandler) onAgentConfigUpdate(updates map[string]state.RawCo if len(mergedConfig.LogLevel) > 0 { // Get the current log level - var newFallback seelog.LogLevel + var newFallback pkglog.LogLevel newFallback, err = pkglog.GetLogLevel() if err == nil { h.configState.FallbackLogLevel = newFallback.String() @@ -113,7 +112,7 @@ func (h *RemoteConfigHandler) onAgentConfigUpdate(updates map[string]state.RawCo } } } else { - var currentLogLevel seelog.LogLevel + var currentLogLevel pkglog.LogLevel currentLogLevel, err = pkglog.GetLogLevel() if err == nil && currentLogLevel.String() == h.configState.LatestLogLevel { pkglog.Infof("Removing remote-config log level override of the trace-agent, falling back to %s", h.configState.FallbackLogLevel) diff --git a/pkg/trace/remoteconfighandler/remote_config_handler_test.go b/pkg/trace/remoteconfighandler/remote_config_handler_test.go index 6d3cde4a49711e..d53ea39325c794 100644 --- a/pkg/trace/remoteconfighandler/remote_config_handler_test.go +++ b/pkg/trace/remoteconfighandler/remote_config_handler_test.go @@ -13,7 +13,6 @@ import ( "strings" "testing" - "github.com/cihub/seelog" "github.com/golang/mock/gomock" "github.com/stretchr/testify/assert" @@ -34,7 +33,7 @@ func TestStart(t *testing.T) { prioritySampler := NewMockprioritySampler(ctrl) errorsSampler := NewMockerrorsSampler(ctrl) rareSampler := NewMockrareSampler(ctrl) - pkglog.SetupLogger(seelog.Default, "debug") + pkglog.SetupLogger(pkglog.Default(), "debug") h := New(&agentConfig, prioritySampler, rareSampler, errorsSampler) @@ -58,7 +57,7 @@ func TestPrioritySampler(t *testing.T) { prioritySampler := NewMockprioritySampler(ctrl) errorsSampler := NewMockerrorsSampler(ctrl) rareSampler := NewMockrareSampler(ctrl) - pkglog.SetupLogger(seelog.Default, "debug") + pkglog.SetupLogger(pkglog.Default(), "debug") agentConfig := config.AgentConfig{RemoteConfigClient: remoteClient, TargetTPS: 41, ErrorTPS: 41, RareSamplerEnabled: true} h := New(&agentConfig, prioritySampler, rareSampler, errorsSampler) @@ -89,7 +88,7 @@ func TestErrorsSampler(t *testing.T) { prioritySampler := NewMockprioritySampler(ctrl) errorsSampler := NewMockerrorsSampler(ctrl) rareSampler := NewMockrareSampler(ctrl) - pkglog.SetupLogger(seelog.Default, "debug") + pkglog.SetupLogger(pkglog.Default(), "debug") agentConfig := config.AgentConfig{RemoteConfigClient: remoteClient, TargetTPS: 41, ErrorTPS: 41, RareSamplerEnabled: true} h := New(&agentConfig, prioritySampler, rareSampler, errorsSampler) @@ -120,7 +119,7 @@ func TestRareSampler(t *testing.T) { prioritySampler := NewMockprioritySampler(ctrl) errorsSampler := NewMockerrorsSampler(ctrl) rareSampler := NewMockrareSampler(ctrl) - pkglog.SetupLogger(seelog.Default, "debug") + pkglog.SetupLogger(pkglog.Default(), "debug") agentConfig := config.AgentConfig{RemoteConfigClient: remoteClient, TargetTPS: 41, ErrorTPS: 41, RareSamplerEnabled: true} h := New(&agentConfig, prioritySampler, rareSampler, errorsSampler) @@ -151,7 +150,7 @@ func TestEnvPrecedence(t *testing.T) { prioritySampler := NewMockprioritySampler(ctrl) errorsSampler := NewMockerrorsSampler(ctrl) rareSampler := NewMockrareSampler(ctrl) - pkglog.SetupLogger(seelog.Default, "debug") + pkglog.SetupLogger(pkglog.Default(), "debug") agentConfig := config.AgentConfig{RemoteConfigClient: remoteClient, TargetTPS: 41, ErrorTPS: 41, RareSamplerEnabled: true, DefaultEnv: "agent-env"} h := New(&agentConfig, prioritySampler, rareSampler, errorsSampler) @@ -193,7 +192,7 @@ func TestLogLevel(t *testing.T) { errorsSampler := NewMockerrorsSampler(ctrl) rareSampler := NewMockrareSampler(ctrl) - pkglog.SetupLogger(seelog.Default, "debug") + pkglog.SetupLogger(pkglog.Default(), "debug") srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, "Bearer fakeToken", r.Header.Get("Authorization")) w.WriteHeader(200) diff --git a/pkg/util/grpc/agent_client_test.go b/pkg/util/grpc/agent_client_test.go index 0bc586fae3fdb6..8fcc62aeb51a37 100644 --- a/pkg/util/grpc/agent_client_test.go +++ b/pkg/util/grpc/agent_client_test.go @@ -11,14 +11,13 @@ import ( "testing" "time" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "github.com/DataDog/datadog-agent/pkg/util/log" ) func TestMain(m *testing.M) { - log.SetupLogger(seelog.Default, "trace") + log.SetupLogger(log.Default(), "trace") os.Exit(m.Run()) } diff --git a/pkg/util/grpc/go.mod b/pkg/util/grpc/go.mod index b058dd317dd343..2cc21e65384f07 100644 --- a/pkg/util/grpc/go.mod +++ b/pkg/util/grpc/go.mod @@ -38,7 +38,6 @@ require ( github.com/DataDog/datadog-agent/pkg/api v0.56.0-rc.3 github.com/DataDog/datadog-agent/pkg/proto v0.56.0-rc.3 github.com/DataDog/datadog-agent/pkg/util/log v0.59.0 - github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/stretchr/testify v1.10.0 golang.org/x/net v0.31.0 @@ -68,6 +67,7 @@ require ( github.com/DataDog/datadog-agent/pkg/version v0.56.0-rc.3 // indirect github.com/DataDog/viper v1.13.5 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect + github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/fsnotify/fsnotify v1.8.0 // indirect github.com/go-ole/go-ole v1.3.0 // indirect diff --git a/pkg/util/kubernetes/apiserver/controllers/wpa_controller_test.go b/pkg/util/kubernetes/apiserver/controllers/wpa_controller_test.go index 89374ba3ea185a..ffc573d99d3558 100644 --- a/pkg/util/kubernetes/apiserver/controllers/wpa_controller_test.go +++ b/pkg/util/kubernetes/apiserver/controllers/wpa_controller_test.go @@ -18,7 +18,6 @@ import ( "github.com/DataDog/watermarkpodautoscaler/apis/datadoghq/v1alpha1" "github.com/cenkalti/backoff" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "gopkg.in/zorkian/go-datadog-api.v2" @@ -654,11 +653,10 @@ func TestWPACRDCheck(t *testing.T) { } func configureLoggerForTest(t *testing.T) func() { - logger, err := seelog.LoggerFromWriterWithMinLevel(testWriter{t}, seelog.TraceLvl) + logger, err := log.LoggerFromWriterWithMinLevel(testWriter{t}, log.TraceLvl) if err != nil { t.Fatalf("unable to configure logger, err: %v", err) } - seelog.ReplaceLogger(logger) //nolint:errcheck log.SetupLogger(logger, "trace") return log.Flush } diff --git a/pkg/util/log/levels.go b/pkg/util/log/levels.go new file mode 100644 index 00000000000000..52e8dd99c49e0f --- /dev/null +++ b/pkg/util/log/levels.go @@ -0,0 +1,47 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +package log + +import "github.com/cihub/seelog" + +// LogLevel is the type of log levels +// +//nolint:revive // keeping the original type name from seelog +type LogLevel seelog.LogLevel + +// Log levels +const ( + TraceLvl LogLevel = seelog.TraceLvl + DebugLvl LogLevel = seelog.DebugLvl + InfoLvl LogLevel = seelog.InfoLvl + WarnLvl LogLevel = seelog.WarnLvl + ErrorLvl LogLevel = seelog.ErrorLvl + CriticalLvl LogLevel = seelog.CriticalLvl + Off LogLevel = seelog.Off +) + +// Log level string representations +const ( + TraceStr = seelog.TraceStr + DebugStr = seelog.DebugStr + InfoStr = seelog.InfoStr + WarnStr = seelog.WarnStr + ErrorStr = seelog.ErrorStr + CriticalStr = seelog.CriticalStr + OffStr = seelog.OffStr +) + +func (level LogLevel) String() string { + return seelog.LogLevel(level).String() +} + +// LogLevelFromString returns a LogLevel from a string +// +//nolint:revive // keeping the original function name from seelog +func LogLevelFromString(levelStr string) (LogLevel, bool) { + level, ok := seelog.LogLevelFromString(levelStr) + return LogLevel(level), ok +} diff --git a/pkg/util/log/log.go b/pkg/util/log/log.go index 0e1ecaa23e3e5b..3eb9ef9fb26795 100644 --- a/pkg/util/log/log.go +++ b/pkg/util/log/log.go @@ -22,7 +22,6 @@ import ( "strings" "sync" - "github.com/cihub/seelog" "go.uber.org/atomic" "github.com/DataDog/datadog-agent/pkg/util/scrubber" @@ -53,9 +52,9 @@ var ( // DatadogLogger wrapper structure for seelog type DatadogLogger struct { - inner seelog.LoggerInterface - level seelog.LogLevel - extra map[string]seelog.LoggerInterface + inner LoggerInterface + level LogLevel + extra map[string]LoggerInterface l sync.RWMutex } @@ -64,7 +63,7 @@ type DatadogLogger struct { */ // SetupLogger setup agent wide logger -func SetupLogger(i seelog.LoggerInterface, level string) { +func SetupLogger(i LoggerInterface, level string) { logger.Store(setupCommonLogger(i, level)) // Flush the log entries logged before initialization now that the logger is initialized @@ -76,17 +75,17 @@ func SetupLogger(i seelog.LoggerInterface, level string) { logsBuffer = []func(){} } -func setupCommonLogger(i seelog.LoggerInterface, level string) *DatadogLogger { +func setupCommonLogger(i LoggerInterface, level string) *DatadogLogger { l := &DatadogLogger{ inner: i, - extra: make(map[string]seelog.LoggerInterface), + extra: make(map[string]LoggerInterface), } - lvl, ok := seelog.LogLevelFromString(level) + lvl, ok := LogLevelFromString(level) if !ok { - lvl = seelog.InfoLvl + lvl = InfoLvl } - l.level = lvl + l.level = LogLevel(lvl) // We're not going to call DatadogLogger directly, but using the // exported functions, that will give us two frames in the stack @@ -121,7 +120,7 @@ func (sw *DatadogLogger) scrub(s string) string { // ChangeLogLevel changes the current log level, valid levels are trace, debug, // info, warn, error, critical and off, it requires a new seelog logger because // an existing one cannot be updated -func ChangeLogLevel(li seelog.LoggerInterface, level string) error { +func ChangeLogLevel(li LoggerInterface, level string) error { if err := logger.changeLogLevel(level); err != nil { return err } @@ -149,36 +148,36 @@ func (sw *loggerPointer) changeLogLevel(level string) error { return errors.New("cannot change loglevel: logger is initialized however logger.inner is nil") } - lvl, ok := seelog.LogLevelFromString(strings.ToLower(level)) + lvl, ok := LogLevelFromString(strings.ToLower(level)) if !ok { return errors.New("bad log level") } - l.level = lvl + l.level = LogLevel(lvl) return nil } // GetLogLevel returns a seelog native representation of the current log level -func GetLogLevel() (seelog.LogLevel, error) { +func GetLogLevel() (LogLevel, error) { return logger.getLogLevel() } -func (sw *loggerPointer) getLogLevel() (seelog.LogLevel, error) { +func (sw *loggerPointer) getLogLevel() (LogLevel, error) { l := sw.Load() if l == nil { - return seelog.InfoLvl, errors.New("cannot get loglevel: logger not initialized") + return InfoLvl, errors.New("cannot get loglevel: logger not initialized") } l.l.RLock() defer l.l.RUnlock() if l.inner == nil { - return seelog.InfoLvl, errors.New("cannot get loglevel: logger not initialized") + return InfoLvl, errors.New("cannot get loglevel: logger not initialized") } return l.level, nil } // ShouldLog returns whether a given log level should be logged by the default logger -func ShouldLog(lvl seelog.LogLevel) bool { +func ShouldLog(lvl LogLevel) bool { // The lock stay in the exported function due to the use of `shouldLog` in function that already hold the lock l := logger.Load() if l != nil { @@ -190,7 +189,7 @@ func ShouldLog(lvl seelog.LogLevel) bool { } // This function should be called with `sw.l` held -func (sw *DatadogLogger) shouldLog(level seelog.LogLevel) bool { +func (sw *DatadogLogger) shouldLog(level LogLevel) bool { return level >= sw.level } @@ -203,7 +202,7 @@ func ValidateLogLevel(logLevel string) (string, error) { seelogLogLevel = "warn" } - if _, found := seelog.LogLevelFromString(seelogLogLevel); !found { + if _, found := LogLevelFromString(seelogLogLevel); !found { return "", fmt.Errorf("unknown log level: %s", seelogLogLevel) } return seelogLogLevel, nil @@ -214,10 +213,10 @@ func ValidateLogLevel(logLevel string) (string, error) { */ // RegisterAdditionalLogger registers an additional logger for logging -func RegisterAdditionalLogger(n string, li seelog.LoggerInterface) error { +func RegisterAdditionalLogger(n string, li LoggerInterface) error { return logger.registerAdditionalLogger(n, li) } -func (sw *loggerPointer) registerAdditionalLogger(n string, li seelog.LoggerInterface) error { +func (sw *loggerPointer) registerAdditionalLogger(n string, li LoggerInterface) error { l := sw.Load() if l == nil { return errors.New("cannot register: logger not initialized") @@ -244,10 +243,10 @@ func (sw *loggerPointer) registerAdditionalLogger(n string, li seelog.LoggerInte } // ReplaceLogger allows replacing the internal logger, returns old logger -func ReplaceLogger(li seelog.LoggerInterface) seelog.LoggerInterface { +func ReplaceLogger(li LoggerInterface) LoggerInterface { return logger.replaceInnerLogger(li) } -func (sw *loggerPointer) replaceInnerLogger(li seelog.LoggerInterface) seelog.LoggerInterface { +func (sw *loggerPointer) replaceInnerLogger(li LoggerInterface) LoggerInterface { l := sw.Load() if l == nil { return nil // Return nil if logger is not initialized @@ -291,7 +290,7 @@ func (sw *loggerPointer) flush() { // log logs a message at the given level, using either bufferFunc (if logging is not yet set up) or // scrubAndLogFunc, and treating the variadic args as the message. -func log(logLevel seelog.LogLevel, bufferFunc func(), scrubAndLogFunc func(string), v ...interface{}) { +func log(logLevel LogLevel, bufferFunc func(), scrubAndLogFunc func(string), v ...interface{}) { l := logger.Load() if l == nil { @@ -310,7 +309,7 @@ func log(logLevel seelog.LogLevel, bufferFunc func(), scrubAndLogFunc func(strin } } -func logWithError(logLevel seelog.LogLevel, bufferFunc func(), scrubAndLogFunc func(string) error, fallbackStderr bool, v ...interface{}) error { +func logWithError(logLevel LogLevel, bufferFunc func(), scrubAndLogFunc func(string) error, fallbackStderr bool, v ...interface{}) error { l := logger.Load() if l == nil { @@ -353,7 +352,7 @@ func logWithError(logLevel seelog.LogLevel, bufferFunc func(), scrubAndLogFunc f * logFormat functions */ -func logFormat(logLevel seelog.LogLevel, bufferFunc func(), scrubAndLogFunc func(string, ...interface{}), format string, params ...interface{}) { +func logFormat(logLevel LogLevel, bufferFunc func(), scrubAndLogFunc func(string, ...interface{}), format string, params ...interface{}) { l := logger.Load() if l == nil { @@ -370,7 +369,7 @@ func logFormat(logLevel seelog.LogLevel, bufferFunc func(), scrubAndLogFunc func scrubAndLogFunc(format, params...) } } -func logFormatWithError(logLevel seelog.LogLevel, bufferFunc func(), scrubAndLogFunc func(string, ...interface{}) error, format string, fallbackStderr bool, params ...interface{}) error { +func logFormatWithError(logLevel LogLevel, bufferFunc func(), scrubAndLogFunc func(string, ...interface{}) error, format string, fallbackStderr bool, params ...interface{}) error { l := logger.Load() if l == nil { @@ -412,7 +411,7 @@ func logFormatWithError(logLevel seelog.LogLevel, bufferFunc func(), scrubAndLog * logContext functions */ -func logContext(logLevel seelog.LogLevel, bufferFunc func(), scrubAndLogFunc func(string), message string, depth int, context ...interface{}) { +func logContext(logLevel LogLevel, bufferFunc func(), scrubAndLogFunc func(string), message string, depth int, context ...interface{}) { l := logger.Load() if l == nil { @@ -433,7 +432,7 @@ func logContext(logLevel seelog.LogLevel, bufferFunc func(), scrubAndLogFunc fun l.inner.SetAdditionalStackDepth(defaultStackDepth) //nolint:errcheck } } -func logContextWithError(logLevel seelog.LogLevel, bufferFunc func(), scrubAndLogFunc func(string) error, message string, fallbackStderr bool, depth int, context ...interface{}) error { +func logContextWithError(logLevel LogLevel, bufferFunc func(), scrubAndLogFunc func(string) error, message string, fallbackStderr bool, depth int, context ...interface{}) error { l := logger.Load() if l == nil { @@ -758,29 +757,29 @@ func formatErrorc(message string, context ...interface{}) error { // Trace logs at the trace level func Trace(v ...interface{}) { - log(seelog.TraceLvl, func() { Trace(v...) }, logger.trace, v...) + log(TraceLvl, func() { Trace(v...) }, logger.trace, v...) } // Tracef logs with format at the trace level func Tracef(format string, params ...interface{}) { - logFormat(seelog.TraceLvl, func() { Tracef(format, params...) }, logger.tracef, format, params...) + logFormat(TraceLvl, func() { Tracef(format, params...) }, logger.tracef, format, params...) } // TracefStackDepth logs with format at the trace level and the current stack depth plus the given depth func TracefStackDepth(depth int, format string, params ...interface{}) { currentLevel, _ := GetLogLevel() - if currentLevel > seelog.TraceLvl { + if currentLevel > TraceLvl { return } msg := fmt.Sprintf(format, params...) - log(seelog.TraceLvl, func() { TraceStackDepth(depth, msg) }, func(s string) { + log(TraceLvl, func() { TraceStackDepth(depth, msg) }, func(s string) { logger.traceStackDepth(s, depth) }, msg) } // TracecStackDepth logs at the trace level with context and the current stack depth plus the additional given one func TracecStackDepth(message string, depth int, context ...interface{}) { - logContext(seelog.TraceLvl, func() { Tracec(message, context...) }, logger.trace, message, depth, context...) + logContext(TraceLvl, func() { Tracec(message, context...) }, logger.trace, message, depth, context...) } // Tracec logs at the trace level with context @@ -791,36 +790,36 @@ func Tracec(message string, context ...interface{}) { // TraceFunc calls and logs the result of 'logFunc' if and only if Trace (or more verbose) logs are enabled func TraceFunc(logFunc func() string) { currentLevel, _ := GetLogLevel() - if currentLevel <= seelog.TraceLvl { + if currentLevel <= TraceLvl { TraceStackDepth(2, logFunc()) } } // Debug logs at the debug level func Debug(v ...interface{}) { - log(seelog.DebugLvl, func() { Debug(v...) }, logger.debug, v...) + log(DebugLvl, func() { Debug(v...) }, logger.debug, v...) } // Debugf logs with format at the debug level func Debugf(format string, params ...interface{}) { - logFormat(seelog.DebugLvl, func() { Debugf(format, params...) }, logger.debugf, format, params...) + logFormat(DebugLvl, func() { Debugf(format, params...) }, logger.debugf, format, params...) } // DebugfStackDepth logs with format at the debug level and the current stack depth plus the given depth func DebugfStackDepth(depth int, format string, params ...interface{}) { currentLevel, _ := GetLogLevel() - if currentLevel > seelog.DebugLvl { + if currentLevel > DebugLvl { return } msg := fmt.Sprintf(format, params...) - log(seelog.DebugLvl, func() { DebugStackDepth(depth, msg) }, func(s string) { + log(DebugLvl, func() { DebugStackDepth(depth, msg) }, func(s string) { logger.debugStackDepth(s, depth) }, msg) } // DebugcStackDepth logs at the debug level with context and the current stack depth plus the additional given one func DebugcStackDepth(message string, depth int, context ...interface{}) { - logContext(seelog.DebugLvl, func() { Debugc(message, context...) }, logger.debug, message, depth, context...) + logContext(DebugLvl, func() { Debugc(message, context...) }, logger.debug, message, depth, context...) } // Debugc logs at the debug level with context @@ -831,36 +830,36 @@ func Debugc(message string, context ...interface{}) { // DebugFunc calls and logs the result of 'logFunc' if and only if Debug (or more verbose) logs are enabled func DebugFunc(logFunc func() string) { currentLevel, _ := GetLogLevel() - if currentLevel <= seelog.DebugLvl { + if currentLevel <= DebugLvl { DebugStackDepth(2, logFunc()) } } // Info logs at the info level func Info(v ...interface{}) { - log(seelog.InfoLvl, func() { Info(v...) }, logger.info, v...) + log(InfoLvl, func() { Info(v...) }, logger.info, v...) } // Infof logs with format at the info level func Infof(format string, params ...interface{}) { - logFormat(seelog.InfoLvl, func() { Infof(format, params...) }, logger.infof, format, params...) + logFormat(InfoLvl, func() { Infof(format, params...) }, logger.infof, format, params...) } // InfofStackDepth logs with format at the info level and the current stack depth plus the given depth func InfofStackDepth(depth int, format string, params ...interface{}) { currentLevel, _ := GetLogLevel() - if currentLevel > seelog.InfoLvl { + if currentLevel > InfoLvl { return } msg := fmt.Sprintf(format, params...) - log(seelog.InfoLvl, func() { InfoStackDepth(depth, msg) }, func(s string) { + log(InfoLvl, func() { InfoStackDepth(depth, msg) }, func(s string) { logger.infoStackDepth(s, depth) }, msg) } // InfocStackDepth logs at the info level with context and the current stack depth plus the additional given one func InfocStackDepth(message string, depth int, context ...interface{}) { - logContext(seelog.InfoLvl, func() { Infoc(message, context...) }, logger.info, message, depth, context...) + logContext(InfoLvl, func() { Infoc(message, context...) }, logger.info, message, depth, context...) } // Infoc logs at the info level with context @@ -871,32 +870,32 @@ func Infoc(message string, context ...interface{}) { // InfoFunc calls and logs the result of 'logFunc' if and only if Info (or more verbose) logs are enabled func InfoFunc(logFunc func() string) { currentLevel, _ := GetLogLevel() - if currentLevel <= seelog.InfoLvl { + if currentLevel <= InfoLvl { InfoStackDepth(2, logFunc()) } } // Warn logs at the warn level and returns an error containing the formated log message func Warn(v ...interface{}) error { - return logWithError(seelog.WarnLvl, func() { _ = Warn(v...) }, logger.warn, false, v...) + return logWithError(WarnLvl, func() { _ = Warn(v...) }, logger.warn, false, v...) } // Warnf logs with format at the warn level and returns an error containing the formated log message func Warnf(format string, params ...interface{}) error { - return logFormatWithError(seelog.WarnLvl, func() { _ = Warnf(format, params...) }, logger.warnf, format, false, params...) + return logFormatWithError(WarnLvl, func() { _ = Warnf(format, params...) }, logger.warnf, format, false, params...) } // WarnfStackDepth logs with format at the warn level and the current stack depth plus the given depth func WarnfStackDepth(depth int, format string, params ...interface{}) error { msg := fmt.Sprintf(format, params...) - return logWithError(seelog.WarnLvl, func() { _ = WarnStackDepth(depth, msg) }, func(s string) error { + return logWithError(WarnLvl, func() { _ = WarnStackDepth(depth, msg) }, func(s string) error { return logger.warnStackDepth(s, depth) }, false, msg) } // WarncStackDepth logs at the warn level with context and the current stack depth plus the additional given one and returns an error containing the formated log message func WarncStackDepth(message string, depth int, context ...interface{}) error { - return logContextWithError(seelog.WarnLvl, func() { _ = Warnc(message, context...) }, logger.warn, message, false, depth, context...) + return logContextWithError(WarnLvl, func() { _ = Warnc(message, context...) }, logger.warn, message, false, depth, context...) } // Warnc logs at the warn level with context and returns an error containing the formated log message @@ -907,32 +906,32 @@ func Warnc(message string, context ...interface{}) error { // WarnFunc calls and logs the result of 'logFunc' if and only if Warn (or more verbose) logs are enabled func WarnFunc(logFunc func() string) { currentLevel, _ := GetLogLevel() - if currentLevel <= seelog.WarnLvl { + if currentLevel <= WarnLvl { _ = WarnStackDepth(2, logFunc()) } } // Error logs at the error level and returns an error containing the formated log message func Error(v ...interface{}) error { - return logWithError(seelog.ErrorLvl, func() { _ = Error(v...) }, logger.error, true, v...) + return logWithError(ErrorLvl, func() { _ = Error(v...) }, logger.error, true, v...) } // Errorf logs with format at the error level and returns an error containing the formated log message func Errorf(format string, params ...interface{}) error { - return logFormatWithError(seelog.ErrorLvl, func() { _ = Errorf(format, params...) }, logger.errorf, format, true, params...) + return logFormatWithError(ErrorLvl, func() { _ = Errorf(format, params...) }, logger.errorf, format, true, params...) } // ErrorfStackDepth logs with format at the error level and the current stack depth plus the given depth func ErrorfStackDepth(depth int, format string, params ...interface{}) error { msg := fmt.Sprintf(format, params...) - return logWithError(seelog.ErrorLvl, func() { _ = ErrorStackDepth(depth, msg) }, func(s string) error { + return logWithError(ErrorLvl, func() { _ = ErrorStackDepth(depth, msg) }, func(s string) error { return logger.errorStackDepth(s, depth) }, true, msg) } // ErrorcStackDepth logs at the error level with context and the current stack depth plus the additional given one and returns an error containing the formated log message func ErrorcStackDepth(message string, depth int, context ...interface{}) error { - return logContextWithError(seelog.ErrorLvl, func() { _ = Errorc(message, context...) }, logger.error, message, true, depth, context...) + return logContextWithError(ErrorLvl, func() { _ = Errorc(message, context...) }, logger.error, message, true, depth, context...) } // Errorc logs at the error level with context and returns an error containing the formated log message @@ -943,32 +942,32 @@ func Errorc(message string, context ...interface{}) error { // ErrorFunc calls and logs the result of 'logFunc' if and only if Error (or more verbose) logs are enabled func ErrorFunc(logFunc func() string) { currentLevel, _ := GetLogLevel() - if currentLevel <= seelog.ErrorLvl { + if currentLevel <= ErrorLvl { _ = ErrorStackDepth(2, logFunc()) } } // Critical logs at the critical level and returns an error containing the formated log message func Critical(v ...interface{}) error { - return logWithError(seelog.CriticalLvl, func() { _ = Critical(v...) }, logger.critical, true, v...) + return logWithError(CriticalLvl, func() { _ = Critical(v...) }, logger.critical, true, v...) } // Criticalf logs with format at the critical level and returns an error containing the formated log message func Criticalf(format string, params ...interface{}) error { - return logFormatWithError(seelog.CriticalLvl, func() { _ = Criticalf(format, params...) }, logger.criticalf, format, true, params...) + return logFormatWithError(CriticalLvl, func() { _ = Criticalf(format, params...) }, logger.criticalf, format, true, params...) } // CriticalfStackDepth logs with format at the critical level and the current stack depth plus the given depth func CriticalfStackDepth(depth int, format string, params ...interface{}) error { msg := fmt.Sprintf(format, params...) - return logWithError(seelog.CriticalLvl, func() { _ = CriticalStackDepth(depth, msg) }, func(s string) error { + return logWithError(CriticalLvl, func() { _ = CriticalStackDepth(depth, msg) }, func(s string) error { return logger.criticalStackDepth(s, depth) }, false, msg) } // CriticalcStackDepth logs at the critical level with context and the current stack depth plus the additional given one and returns an error containing the formated log message func CriticalcStackDepth(message string, depth int, context ...interface{}) error { - return logContextWithError(seelog.CriticalLvl, func() { _ = Criticalc(message, context...) }, logger.critical, message, true, depth, context...) + return logContextWithError(CriticalLvl, func() { _ = Criticalc(message, context...) }, logger.critical, message, true, depth, context...) } // Criticalc logs at the critical level with context and returns an error containing the formated log message @@ -979,49 +978,49 @@ func Criticalc(message string, context ...interface{}) error { // CriticalFunc calls and logs the result of 'logFunc' if and only if Critical (or more verbose) logs are enabled func CriticalFunc(logFunc func() string) { currentLevel, _ := GetLogLevel() - if currentLevel <= seelog.CriticalLvl { + if currentLevel <= CriticalLvl { _ = CriticalStackDepth(2, logFunc()) } } // InfoStackDepth logs at the info level and the current stack depth plus the additional given one func InfoStackDepth(depth int, v ...interface{}) { - log(seelog.InfoLvl, func() { InfoStackDepth(depth, v...) }, func(s string) { + log(InfoLvl, func() { InfoStackDepth(depth, v...) }, func(s string) { logger.infoStackDepth(s, depth) }, v...) } // WarnStackDepth logs at the warn level and the current stack depth plus the additional given one and returns an error containing the formated log message func WarnStackDepth(depth int, v ...interface{}) error { - return logWithError(seelog.WarnLvl, func() { _ = WarnStackDepth(depth, v...) }, func(s string) error { + return logWithError(WarnLvl, func() { _ = WarnStackDepth(depth, v...) }, func(s string) error { return logger.warnStackDepth(s, depth) }, false, v...) } // DebugStackDepth logs at the debug level and the current stack depth plus the additional given one and returns an error containing the formated log message func DebugStackDepth(depth int, v ...interface{}) { - log(seelog.DebugLvl, func() { DebugStackDepth(depth, v...) }, func(s string) { + log(DebugLvl, func() { DebugStackDepth(depth, v...) }, func(s string) { logger.debugStackDepth(s, depth) }, v...) } // TraceStackDepth logs at the trace level and the current stack depth plus the additional given one and returns an error containing the formated log message func TraceStackDepth(depth int, v ...interface{}) { - log(seelog.TraceLvl, func() { TraceStackDepth(depth, v...) }, func(s string) { + log(TraceLvl, func() { TraceStackDepth(depth, v...) }, func(s string) { logger.traceStackDepth(s, depth) }, v...) } // ErrorStackDepth logs at the error level and the current stack depth plus the additional given one and returns an error containing the formated log message func ErrorStackDepth(depth int, v ...interface{}) error { - return logWithError(seelog.ErrorLvl, func() { _ = ErrorStackDepth(depth, v...) }, func(s string) error { + return logWithError(ErrorLvl, func() { _ = ErrorStackDepth(depth, v...) }, func(s string) error { return logger.errorStackDepth(s, depth) }, true, v...) } // CriticalStackDepth logs at the critical level and the current stack depth plus the additional given one and returns an error containing the formated log message func CriticalStackDepth(depth int, v ...interface{}) error { - return logWithError(seelog.CriticalLvl, func() { _ = CriticalStackDepth(depth, v...) }, func(s string) error { + return logWithError(CriticalLvl, func() { _ = CriticalStackDepth(depth, v...) }, func(s string) error { return logger.criticalStackDepth(s, depth) }, true, v...) } @@ -1032,15 +1031,15 @@ func CriticalStackDepth(depth int, v ...interface{}) error { // JMXError Logs for JMX check func JMXError(v ...interface{}) error { - return logWithError(seelog.ErrorLvl, func() { _ = JMXError(v...) }, jmxLogger.error, true, v...) + return logWithError(ErrorLvl, func() { _ = JMXError(v...) }, jmxLogger.error, true, v...) } // JMXInfo Logs func JMXInfo(v ...interface{}) { - log(seelog.InfoLvl, func() { JMXInfo(v...) }, jmxLogger.info, v...) + log(InfoLvl, func() { JMXInfo(v...) }, jmxLogger.info, v...) } // SetupJMXLogger setup JMXfetch specific logger -func SetupJMXLogger(i seelog.LoggerInterface, level string) { +func SetupJMXLogger(i LoggerInterface, level string) { jmxLogger.Store(setupCommonLogger(i, level)) } diff --git a/pkg/util/log/log_bench_test.go b/pkg/util/log/log_bench_test.go index 61ab1ec8ccbc3d..bf700aae85e754 100644 --- a/pkg/util/log/log_bench_test.go +++ b/pkg/util/log/log_bench_test.go @@ -9,15 +9,13 @@ import ( "bufio" "bytes" "testing" - - "github.com/cihub/seelog" ) func BenchmarkLogVanilla(b *testing.B) { var buff bytes.Buffer w := bufio.NewWriter(&buff) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, DebugLvl, "[%LEVEL] %FuncShort: %Msg") for n := 0; n < b.N; n++ { l.Infof("this is a credential encoding uri: %s", "http://user:password@host:port") @@ -28,7 +26,7 @@ func BenchmarkLogVanillaLevels(b *testing.B) { var buff bytes.Buffer w := bufio.NewWriter(&buff) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.InfoLvl, "[%LEVEL] %FuncShort: %Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, InfoLvl, "[%LEVEL] %FuncShort: %Msg") for n := 0; n < b.N; n++ { l.Debugf("this is a credential encoding uri: %s", "http://user:password@host:port") @@ -39,7 +37,7 @@ func BenchmarkLogScrubbing(b *testing.B) { var buff bytes.Buffer w := bufio.NewWriter(&buff) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, DebugLvl, "[%LEVEL] %FuncShort: %Msg") SetupLogger(l, "info") for n := 0; n < b.N; n++ { @@ -51,7 +49,7 @@ func BenchmarkLogScrubbingLevels(b *testing.B) { var buff bytes.Buffer w := bufio.NewWriter(&buff) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, DebugLvl, "[%LEVEL] %FuncShort: %Msg") SetupLogger(l, "info") for n := 0; n < b.N; n++ { @@ -64,8 +62,8 @@ func BenchmarkLogScrubbingMulti(b *testing.B) { wA := bufio.NewWriter(&buffA) wB := bufio.NewWriter(&buffB) - lA, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(wA, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") - lB, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(wB, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + lA, _ := LoggerFromWriterWithMinLevelAndFormat(wA, DebugLvl, "[%LEVEL] %FuncShort: %Msg") + lB, _ := LoggerFromWriterWithMinLevelAndFormat(wB, DebugLvl, "[%LEVEL] %FuncShort: %Msg") SetupLogger(lA, "info") _ = RegisterAdditionalLogger("extra", lB) @@ -82,7 +80,7 @@ func BenchmarkLogWithContext(b *testing.B) { var buff bytes.Buffer w := bufio.NewWriter(&buff) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, DebugLvl, "[%LEVEL] %FuncShort: %Msg") SetupLogger(l, "info") for n := 0; n < b.N; n++ { diff --git a/pkg/util/log/log_not_serverless_test.go b/pkg/util/log/log_not_serverless_test.go index 5bc245912cc49e..c6849777386024 100644 --- a/pkg/util/log/log_not_serverless_test.go +++ b/pkg/util/log/log_not_serverless_test.go @@ -12,7 +12,6 @@ import ( "bytes" "testing" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" ) @@ -20,7 +19,7 @@ func TestServerlessLoggingNotInServerlessContext(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevel(w, seelog.DebugLvl) + l, err := LoggerFromWriterWithMinLevel(w, DebugLvl) assert.NoError(t, err) SetupLogger(l, "debug") diff --git a/pkg/util/log/log_serverless_test.go b/pkg/util/log/log_serverless_test.go index cb9c2ed83b9a33..a6520631ce7419 100644 --- a/pkg/util/log/log_serverless_test.go +++ b/pkg/util/log/log_serverless_test.go @@ -12,7 +12,6 @@ import ( "bytes" "testing" - "github.com/cihub/seelog" "github.com/stretchr/testify/assert" ) @@ -20,7 +19,7 @@ func TestServerlessLoggingInServerlessContext(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevel(w, seelog.DebugLvl) + l, err := LoggerFromWriterWithMinLevel(w, DebugLvl) assert.NoError(t, err) SetupLogger(l, "debug") diff --git a/pkg/util/log/log_test.go b/pkg/util/log/log_test.go index b6af55dd37c7cc..ca1bbf45d737ac 100644 --- a/pkg/util/log/log_test.go +++ b/pkg/util/log/log_test.go @@ -49,7 +49,7 @@ func TestBasicLogging(t *testing.T) { w := bufio.NewWriter(&b) seelog.RegisterCustomFormatter("ExtraTextContext", createExtraTextContext) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %ExtraTextContext%Msg\n") + l, err := LoggerFromWriterWithMinLevelAndFormat(w, DebugLvl, "[%LEVEL] %FuncShort: %ExtraTextContext%Msg\n") assert.NoError(t, err) SetupLogger(l, "debug") @@ -108,7 +108,7 @@ func TestLogBuffer(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := LoggerFromWriterWithMinLevelAndFormat(w, DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.NoError(t, err) Tracef("%s", "foo") @@ -134,7 +134,7 @@ func TestLogBufferWithContext(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := LoggerFromWriterWithMinLevelAndFormat(w, DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.NoError(t, err) Tracec("baz", "number", 1, "str", "hello") @@ -170,7 +170,7 @@ func TestCredentialScrubbingLogging(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := LoggerFromWriterWithMinLevelAndFormat(w, DebugLvl, "[%LEVEL] %FuncShort: %Msg") assert.NoError(t, err) SetupLogger(l, "info") @@ -192,9 +192,9 @@ func TestExtraLogging(t *testing.T) { w := bufio.NewWriter(&a) wA := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %Msg") + l, err := LoggerFromWriterWithMinLevelAndFormat(w, DebugLvl, "[%LEVEL] %Msg") assert.NoError(t, err) - lA, err := seelog.LoggerFromWriterWithMinLevelAndFormat(wA, seelog.DebugLvl, "[%LEVEL] %Msg") + lA, err := LoggerFromWriterWithMinLevelAndFormat(wA, DebugLvl, "[%LEVEL] %Msg") assert.NoError(t, err) SetupLogger(l, "info") @@ -244,7 +244,7 @@ func TestWarnNotNil(t *testing.T) { assert.NotNil(t, Warn("test")) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.CriticalLvl, "[%LEVEL] %FuncShort: %Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, CriticalLvl, "[%LEVEL] %FuncShort: %Msg") SetupLogger(l, "critical") assert.NotNil(t, Warn("test")) @@ -260,7 +260,7 @@ func TestWarnfNotNil(t *testing.T) { assert.NotNil(t, Warn("test")) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.CriticalLvl, "[%LEVEL] %FuncShort: %Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, CriticalLvl, "[%LEVEL] %FuncShort: %Msg") SetupLogger(l, "critical") assert.NotNil(t, Warn("test")) @@ -277,7 +277,7 @@ func TestWarncNotNil(t *testing.T) { assert.NotNil(t, Warnc("test", "key", "val")) seelog.RegisterCustomFormatter("ExtraTextContext", createExtraTextContext) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.CriticalLvl, "[%LEVEL] %FuncShort: %ExtraTextContext%Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, CriticalLvl, "[%LEVEL] %FuncShort: %ExtraTextContext%Msg") SetupLogger(l, "critical") assert.NotNil(t, Warnc("test", "key", "val")) @@ -293,7 +293,7 @@ func TestErrorNotNil(t *testing.T) { assert.NotNil(t, Error("test")) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.CriticalLvl, "[%LEVEL] %FuncShort: %Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, CriticalLvl, "[%LEVEL] %FuncShort: %Msg") SetupLogger(l, "critical") assert.NotNil(t, Error("test")) @@ -309,7 +309,7 @@ func TestErrorfNotNil(t *testing.T) { assert.NotNil(t, Errorf("test")) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.CriticalLvl, "[%LEVEL] %FuncShort: %Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, CriticalLvl, "[%LEVEL] %FuncShort: %Msg") SetupLogger(l, "critical") assert.NotNil(t, Errorf("test")) @@ -326,7 +326,7 @@ func TestErrorcNotNil(t *testing.T) { assert.NotNil(t, Errorc("test", "key", "val")) seelog.RegisterCustomFormatter("ExtraTextContext", createExtraTextContext) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.CriticalLvl, "[%LEVEL] %FuncShort: %ExtraTextContext%Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, CriticalLvl, "[%LEVEL] %FuncShort: %ExtraTextContext%Msg") SetupLogger(l, "critical") assert.NotNil(t, Errorc("test", "key", "val")) @@ -342,7 +342,7 @@ func TestCriticalNotNil(t *testing.T) { assert.NotNil(t, Critical("test")) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.InfoLvl, "[%LEVEL] %FuncShort: %Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, InfoLvl, "[%LEVEL] %FuncShort: %Msg") SetupLogger(l, "info") assert.NotNil(t, Critical("test")) @@ -354,7 +354,7 @@ func TestCriticalfNotNil(t *testing.T) { assert.NotNil(t, Criticalf("test")) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.InfoLvl, "[%LEVEL] %FuncShort: %Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, InfoLvl, "[%LEVEL] %FuncShort: %Msg") SetupLogger(l, "info") assert.NotNil(t, Criticalf("test")) @@ -367,7 +367,7 @@ func TestCriticalcNotNil(t *testing.T) { assert.NotNil(t, Criticalc("test", "key", "val")) seelog.RegisterCustomFormatter("ExtraTextContext", createExtraTextContext) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.InfoLvl, "[%LEVEL] %FuncShort: %ExtraTextContext%Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, InfoLvl, "[%LEVEL] %FuncShort: %ExtraTextContext%Msg") SetupLogger(l, "info") assert.NotNil(t, Criticalc("test", "key", "val")) @@ -377,7 +377,7 @@ func TestDebugFuncNoExecute(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.InfoLvl, "[%LEVEL] %FuncShort: %Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, InfoLvl, "[%LEVEL] %FuncShort: %Msg") SetupLogger(l, "info") i := 0 @@ -393,7 +393,7 @@ func TestDebugFuncExecute(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.DebugLvl, "[%LEVEL] %FuncShort: %Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, DebugLvl, "[%LEVEL] %FuncShort: %Msg") SetupLogger(l, "debug") i := 0 @@ -410,37 +410,37 @@ func TestDebugFuncExecute(t *testing.T) { func TestFuncVersions(t *testing.T) { cases := []struct { - seelogLevel seelog.LogLevel + seelogLevel LogLevel strLogLevel string logFunc func(func() string) expectedToBeCalled bool }{ - {seelog.ErrorLvl, "error", DebugFunc, false}, - {seelog.WarnLvl, "warn", DebugFunc, false}, - {seelog.InfoLvl, "info", DebugFunc, false}, - {seelog.DebugLvl, "debug", DebugFunc, true}, - {seelog.TraceLvl, "trace", DebugFunc, true}, + {ErrorLvl, "error", DebugFunc, false}, + {WarnLvl, "warn", DebugFunc, false}, + {InfoLvl, "info", DebugFunc, false}, + {DebugLvl, "debug", DebugFunc, true}, + {TraceLvl, "trace", DebugFunc, true}, - {seelog.TraceLvl, "trace", TraceFunc, true}, - {seelog.InfoLvl, "info", TraceFunc, false}, + {TraceLvl, "trace", TraceFunc, true}, + {InfoLvl, "info", TraceFunc, false}, - {seelog.InfoLvl, "info", InfoFunc, true}, - {seelog.WarnLvl, "warn", InfoFunc, false}, + {InfoLvl, "info", InfoFunc, true}, + {WarnLvl, "warn", InfoFunc, false}, - {seelog.WarnLvl, "warn", WarnFunc, true}, - {seelog.ErrorLvl, "error", WarnFunc, false}, + {WarnLvl, "warn", WarnFunc, true}, + {ErrorLvl, "error", WarnFunc, false}, - {seelog.ErrorLvl, "error", ErrorFunc, true}, - {seelog.CriticalLvl, "critical", ErrorFunc, false}, + {ErrorLvl, "error", ErrorFunc, true}, + {CriticalLvl, "critical", ErrorFunc, false}, - {seelog.CriticalLvl, "critical", CriticalFunc, true}, + {CriticalLvl, "critical", CriticalFunc, true}, } for _, tc := range cases { var b bytes.Buffer w := bufio.NewWriter(&b) - l, _ := seelog.LoggerFromWriterWithMinLevelAndFormat(w, tc.seelogLevel, "[%LEVEL] %FuncShort: %Msg") + l, _ := LoggerFromWriterWithMinLevelAndFormat(w, tc.seelogLevel, "[%LEVEL] %FuncShort: %Msg") SetupLogger(l, tc.strLogLevel) i := 0 @@ -463,16 +463,16 @@ func TestStackDepthfLogging(t *testing.T) { const stackDepth = 1 cases := []struct { - seelogLevel seelog.LogLevel + seelogLevel LogLevel strLogLevel string expectedToBeCalled int }{ - {seelog.CriticalLvl, "critical", 1}, - {seelog.ErrorLvl, "error", 2}, - {seelog.WarnLvl, "warn", 3}, - {seelog.InfoLvl, "info", 4}, - {seelog.DebugLvl, "debug", 5}, - {seelog.TraceLvl, "trace", 6}, + {CriticalLvl, "critical", 1}, + {ErrorLvl, "error", 2}, + {WarnLvl, "warn", 3}, + {InfoLvl, "info", 4}, + {DebugLvl, "debug", 5}, + {TraceLvl, "trace", 6}, } for _, tc := range cases { @@ -480,7 +480,7 @@ func TestStackDepthfLogging(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, tc.seelogLevel, "[%LEVEL] %Func: %Msg\n") + l, err := LoggerFromWriterWithMinLevelAndFormat(w, tc.seelogLevel, "[%LEVEL] %Func: %Msg\n") assert.NoError(t, err) SetupLogger(l, tc.strLogLevel) @@ -529,7 +529,7 @@ func getFuncName(val reflect.Value) (string, error) { func TestLoggerScrubbingCount(t *testing.T) { var b bytes.Buffer w := bufio.NewWriter(&b) - l, err := seelog.LoggerFromWriterWithMinLevelAndFormat(w, seelog.TraceLvl, "[%LEVEL] %FuncShort: %Msg") + l, err := LoggerFromWriterWithMinLevelAndFormat(w, TraceLvl, "[%LEVEL] %FuncShort: %Msg") require.NoError(t, err) SetupLogger(l, "trace") diff --git a/pkg/util/log/log_test_init.go b/pkg/util/log/log_test_init.go index 7dd6bcd7e3c7c3..b1b5e3bbedba24 100644 --- a/pkg/util/log/log_test_init.go +++ b/pkg/util/log/log_test_init.go @@ -9,8 +9,6 @@ package log import ( "os" - - "github.com/cihub/seelog" ) func init() { @@ -18,5 +16,5 @@ func init() { if level == "" { level = "debug" } - SetupLogger(seelog.Default, level) + SetupLogger(Default(), level) } diff --git a/pkg/util/log/logger.go b/pkg/util/log/logger.go new file mode 100644 index 00000000000000..5de956c854f079 --- /dev/null +++ b/pkg/util/log/logger.go @@ -0,0 +1,35 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +package log + +import ( + "io" + + "github.com/cihub/seelog" +) + +// LoggerInterface provides basic logging methods. +type LoggerInterface seelog.LoggerInterface + +// Default returns a default logger +func Default() LoggerInterface { + return seelog.Default +} + +// Disabled returns a disabled logger +func Disabled() LoggerInterface { + return seelog.Disabled +} + +// LoggerFromWriterWithMinLevelAndFormat creates a new logger from a writer, a minimum log level and a format. +func LoggerFromWriterWithMinLevelAndFormat(output io.Writer, minLevel LogLevel, format string) (LoggerInterface, error) { + return seelog.LoggerFromWriterWithMinLevelAndFormat(output, seelog.LogLevel(minLevel), format) +} + +// LoggerFromWriterWithMinLevel creates a new logger from a writer and a minimum log level. +func LoggerFromWriterWithMinLevel(output io.Writer, minLevel LogLevel) (LoggerInterface, error) { + return seelog.LoggerFromWriterWithMinLevel(output, seelog.LogLevel(minLevel)) +} diff --git a/pkg/util/log/setup/log.go b/pkg/util/log/setup/log.go index 959918853ba554..87b8a27da455ae 100644 --- a/pkg/util/log/setup/log.go +++ b/pkg/util/log/setup/log.go @@ -246,29 +246,29 @@ type logWriter struct { } // NewLogWriter returns a logWriter set with given logLevel. Returns an error if logLevel is unknown/not set. -func NewLogWriter(additionalDepth int, logLevel seelog.LogLevel) (io.Writer, error) { +func NewLogWriter(additionalDepth int, logLevel log.LogLevel) (io.Writer, error) { writer := &logWriter{ additionalDepth: additionalDepth, } switch logLevel { - case seelog.TraceLvl: + case log.TraceLvl: writer.logFunc = log.TraceStackDepth - case seelog.DebugLvl: + case log.DebugLvl: writer.logFunc = log.DebugStackDepth - case seelog.InfoLvl: + case log.InfoLvl: writer.logFunc = log.InfoStackDepth - case seelog.WarnLvl: + case log.WarnLvl: writer.logFunc = func(dept int, v ...interface{}) { _ = log.WarnStackDepth(dept, v...) } writer.additionalDepth++ - case seelog.ErrorLvl: + case log.ErrorLvl: writer.logFunc = func(dept int, v ...interface{}) { _ = log.ErrorStackDepth(dept, v...) } writer.additionalDepth++ - case seelog.CriticalLvl: + case log.CriticalLvl: writer.logFunc = func(dept int, v ...interface{}) { _ = log.CriticalStackDepth(dept, v...) } @@ -294,7 +294,7 @@ type tlsHandshakeErrorWriter struct { } // NewTLSHandshakeErrorWriter is a wrapper function which creates a new logWriter. -func NewTLSHandshakeErrorWriter(additionalDepth int, logLevel seelog.LogLevel) (io.Writer, error) { +func NewTLSHandshakeErrorWriter(additionalDepth int, logLevel log.LogLevel) (io.Writer, error) { logWriter, err := NewLogWriter(additionalDepth, logLevel) if err != nil { return nil, err diff --git a/pkg/util/log/zap/zapcore.go b/pkg/util/log/zap/zapcore.go index 576e443557f21e..4d77c3e1c86127 100644 --- a/pkg/util/log/zap/zapcore.go +++ b/pkg/util/log/zap/zapcore.go @@ -7,7 +7,6 @@ package log import ( - "github.com/cihub/seelog" "go.uber.org/zap/zapcore" "github.com/DataDog/datadog-agent/pkg/util/log" @@ -20,18 +19,18 @@ type core struct { } func (c *core) Enabled(level zapcore.Level) bool { - var seelogLevel seelog.LogLevel + var seelogLevel log.LogLevel switch level { case zapcore.DebugLevel: - seelogLevel = seelog.DebugLvl + seelogLevel = log.DebugLvl case zapcore.InfoLevel: - seelogLevel = seelog.InfoLvl + seelogLevel = log.InfoLvl case zapcore.WarnLevel: - seelogLevel = seelog.WarnLvl + seelogLevel = log.WarnLvl case zapcore.ErrorLevel: - seelogLevel = seelog.ErrorLvl + seelogLevel = log.ErrorLvl case zapcore.DPanicLevel, zapcore.PanicLevel, zapcore.FatalLevel: - seelogLevel = seelog.CriticalLvl + seelogLevel = log.CriticalLvl } return log.ShouldLog(seelogLevel) } diff --git a/pkg/util/winutil/eventlog/subscription/subscription_test.go b/pkg/util/winutil/eventlog/subscription/subscription_test.go index bc59447aec2b77..f9ba0b1cca4963 100644 --- a/pkg/util/winutil/eventlog/subscription/subscription_test.go +++ b/pkg/util/winutil/eventlog/subscription/subscription_test.go @@ -13,11 +13,10 @@ import ( "testing" pkglog "github.com/DataDog/datadog-agent/pkg/util/log" - "github.com/cihub/seelog" - "github.com/DataDog/datadog-agent/pkg/util/winutil/eventlog/api" - "github.com/DataDog/datadog-agent/pkg/util/winutil/eventlog/bookmark" - "github.com/DataDog/datadog-agent/pkg/util/winutil/eventlog/test" + evtapi "github.com/DataDog/datadog-agent/pkg/util/winutil/eventlog/api" + evtbookmark "github.com/DataDog/datadog-agent/pkg/util/winutil/eventlog/bookmark" + eventlog_test "github.com/DataDog/datadog-agent/pkg/util/winutil/eventlog/test" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -31,7 +30,7 @@ var debuglogFlag = flag.Bool("debuglog", false, "Enable seelog debug logging") func optEnableDebugLogging() { // Enable logger if *debuglogFlag { - pkglog.SetupLogger(seelog.Default, "debug") + pkglog.SetupLogger(pkglog.Default(), "debug") } } diff --git a/pkg/util/winutil/go.mod b/pkg/util/winutil/go.mod index f23d0e841a613f..397b907b11f961 100644 --- a/pkg/util/winutil/go.mod +++ b/pkg/util/winutil/go.mod @@ -9,7 +9,6 @@ replace ( require ( github.com/DataDog/datadog-agent/pkg/util/log v0.56.0-rc.3 - github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 github.com/fsnotify/fsnotify v1.8.0 github.com/stretchr/testify v1.10.0 go.uber.org/atomic v1.11.0 @@ -18,6 +17,7 @@ require ( require ( github.com/DataDog/datadog-agent/pkg/util/scrubber v0.56.0-rc.3 // indirect + github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/kr/text v0.2.0 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect