Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASCII-2578] Remove seelog imports outside pkg/util/log #31788

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions cmd/agent/common/common_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ 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"
"github.com/DataDog/datadog-agent/comp/core/autodiscovery"
"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"
)

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions cmd/cluster-agent/admission/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions cmd/cluster-agent/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/security-agent/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions cmd/trace-agent/test/testsuite/config_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand Down
5 changes: 1 addition & 4 deletions comp/api/api/apiimpl/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion comp/core/log/mock/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.1
github.com/DataDog/datadog-agent/pkg/util/log/setup v0.0.0-00010101000000-000000000000
github.com/cihub/seelog v0.0.0-20170130134532-f561c5e57575
)

require (
Expand All @@ -43,6 +42,7 @@ require (
github.com/DataDog/datadog-agent/pkg/util/scrubber v0.59.1 // indirect
github.com/DataDog/datadog-agent/pkg/version v0.59.1 // 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
Expand Down
6 changes: 2 additions & 4 deletions comp/core/log/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -37,15 +35,15 @@ 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())
}

t.Cleanup(func() {
// stop using the logger to avoid a race condition
pkglog.ChangeLogLevel(seelog.Default, "debug")
pkglog.ChangeLogLevel(pkglog.Default(), "debug")
iface.Flush()
})

Expand Down
8 changes: 4 additions & 4 deletions comp/dogstatsd/serverDebug/serverdebugimpl/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"time"

"github.com/benbjohnson/clock"
slog "github.com/cihub/seelog"
"go.uber.org/atomic"
"go.uber.org/fx"

Expand All @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions comp/netflow/flowaggregator/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")

Expand Down
15 changes: 7 additions & 8 deletions comp/netflow/goflowlib/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")

Expand Down
3 changes: 1 addition & 2 deletions comp/remote-config/rcclient/rcclientimpl/rcclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions comp/trace/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
Loading
Loading