Skip to content

Commit

Permalink
Remove custom log leveler (#985)
Browse files Browse the repository at this point in the history
Instead of manually using a log leveler, rely on the global one defined
in the `log` package.
  • Loading branch information
mcastorina committed Dec 21, 2022
1 parent 130d5ae commit 8859771
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/gorilla/mux"
"github.com/jpillora/overseer"
"github.com/sirupsen/logrus"
"go.uber.org/zap"
"gopkg.in/alecthomas/kingpin.v2"

"github.com/trufflesecurity/trufflehog/v3/pkg/common"
Expand Down Expand Up @@ -96,8 +95,6 @@ var (
syslogTLSCert = syslogScan.Flag("cert", "Path to TLS cert.").String()
syslogTLSKey = syslogScan.Flag("key", "Path to TLS key.").String()
syslogFormat = syslogScan.Flag("format", "Log format. Can be rfc3164 or rfc5424").String()

logLevel = zap.NewAtomicLevel()
)

func init() {
Expand All @@ -118,12 +115,10 @@ func init() {
switch {
case *trace:
log.SetLevel(5)
log.SetLevelForControl(logLevel, 5)
logrus.SetLevel(logrus.TraceLevel)
logrus.Debugf("running version %s", version.BuildVersion)
case *debug:
log.SetLevel(2)
log.SetLevelForControl(logLevel, 2)
logrus.SetLevel(logrus.DebugLevel)
logrus.Debugf("running version %s", version.BuildVersion)
default:
Expand Down Expand Up @@ -180,9 +175,8 @@ func run(state overseer.State) {
}
}()
}
logger, sync := log.New("trufflehog", log.WithConsoleSink(os.Stderr, log.WithLeveler(logLevel)))
ctx := context.WithLogger(context.TODO(), logger)

logger, sync := log.New("trufflehog", log.WithConsoleSink(os.Stderr))
context.SetDefaultLogger(logger)
defer func() { _ = sync() }()

conf := &config.Config{}
Expand All @@ -195,6 +189,7 @@ func run(state overseer.State) {
}
}

ctx := context.TODO()
e := engine.Start(ctx,
engine.WithConcurrency(*concurrency),
engine.WithDecoders(decoders.DefaultDecoders()...),
Expand Down

0 comments on commit 8859771

Please sign in to comment.