diff --git a/cmd/crowdsec-cli/capi.go b/cmd/crowdsec-cli/capi.go index 54a4fbebe..5af2739b3 100644 --- a/cmd/crowdsec-cli/capi.go +++ b/cmd/crowdsec-cli/capi.go @@ -98,7 +98,7 @@ func NewCapiCmd() *cobra.Command { fmt.Printf("%s\n", string(apiConfigDump)) } - log.Warningf(ReloadMessage()) + log.Warning(ReloadMessage()) }, } cmdCapiRegister.Flags().StringVarP(&outputFile, "file", "f", "", "output file destination") diff --git a/cmd/crowdsec-cli/console.go b/cmd/crowdsec-cli/console.go index df26bcf05..c1818d2a8 100644 --- a/cmd/crowdsec-cli/console.go +++ b/cmd/crowdsec-cli/console.go @@ -108,7 +108,7 @@ After running this command your will need to validate the enrollment in the weba log.Fatalf("Could not enroll instance: %s", err) } if resp.Response.StatusCode == 200 && !overwrite { - log.Warningf("Instance already enrolled. You can use '--overwrite' to force enroll") + log.Warning("Instance already enrolled. You can use '--overwrite' to force enroll") return } diff --git a/cmd/crowdsec-cli/lapi.go b/cmd/crowdsec-cli/lapi.go index 50b97aa42..80f909759 100644 --- a/cmd/crowdsec-cli/lapi.go +++ b/cmd/crowdsec-cli/lapi.go @@ -111,7 +111,7 @@ Keep in mind the machine needs to be validated by an administrator on LAPI side } else { fmt.Printf("%s\n", string(apiConfigDump)) } - log.Warningf(ReloadMessage()) + log.Warning(ReloadMessage()) }, } cmdLapiRegister.Flags().StringVarP(&apiURL, "url", "u", "", "URL of the API (ie. http://127.0.0.1)") diff --git a/cmd/crowdsec-cli/metrics.go b/cmd/crowdsec-cli/metrics.go index 497f4fcfc..02ca56f55 100644 --- a/cmd/crowdsec-cli/metrics.go +++ b/cmd/crowdsec-cli/metrics.go @@ -400,7 +400,7 @@ func NewMetricsCmd() *cobra.Command { log.Fatalf(err.Error()) } if !csConfig.Prometheus.Enabled { - log.Warningf("Prometheus is not enabled, can't show metrics") + log.Warning("Prometheus is not enabled, can't show metrics") os.Exit(1) } diff --git a/cmd/crowdsec/crowdsec.go b/cmd/crowdsec/crowdsec.go index 433f453c4..ddb263368 100644 --- a/cmd/crowdsec/crowdsec.go +++ b/cmd/crowdsec/crowdsec.go @@ -123,7 +123,7 @@ func runCrowdsec(cConfig *csconfig.Config, parsers *parser.Parsers) error { } } - log.Warningf("Starting processing data") + log.Info("Starting processing data") if err := acquisition.StartAcquisition(dataSources, inputLineChan, &acquisTomb); err != nil { log.Fatalf("starting acquisition error : %s", err) @@ -228,7 +228,7 @@ func waitOnTomb() { case <-acquisTomb.Dead(): /*if it's acquisition dying it means that we were in "cat" mode. while shutting down, we need to give time for all buckets to process in flight data*/ - log.Warningf("Acquisition is finished, shutting down") + log.Warning("Acquisition is finished, shutting down") /* While it might make sense to want to shut-down parser/buckets/etc. as soon as acquisition is finished, we might have some pending buckets: buckets that overflowed, but whose LeakRoutine are still alive because they diff --git a/cmd/crowdsec/main.go b/cmd/crowdsec/main.go index b88a84f5e..76fd53a0d 100644 --- a/cmd/crowdsec/main.go +++ b/cmd/crowdsec/main.go @@ -57,6 +57,7 @@ type Flags struct { TraceLevel bool DebugLevel bool InfoLevel bool + WarnLevel bool PrintVersion bool SingleFileType string Labels map[string]string @@ -181,8 +182,9 @@ func (f *Flags) Parse() { flag.StringVar(&f.ConfigFile, "c", csconfig.DefaultConfigPath("config.yaml"), "configuration file") flag.BoolVar(&f.TraceLevel, "trace", false, "VERY verbose") - flag.BoolVar(&f.DebugLevel, "debug", false, "print debug-level on stdout") - flag.BoolVar(&f.InfoLevel, "info", false, "print info-level on stdout") + flag.BoolVar(&f.DebugLevel, "debug", false, "print debug-level on stderr") + flag.BoolVar(&f.InfoLevel, "info", false, "print info-level on stderr") + flag.BoolVar(&f.WarnLevel, "warning", false, "print warning-level on stderr") flag.BoolVar(&f.PrintVersion, "version", false, "display version") flag.StringVar(&f.OneShotDSN, "dsn", "", "Process a single data source in time-machine") flag.StringVar(&f.SingleFileType, "type", "", "Labels.type for file in time-machine") @@ -224,14 +226,18 @@ func LoadConfig(cConfig *csconfig.Config) error { return errors.New("You must run at least the API Server or crowdsec") } - if flags.DebugLevel { - logLevel := log.DebugLevel + if flags.WarnLevel { + logLevel := log.WarnLevel cConfig.Common.LogLevel = &logLevel } if flags.InfoLevel || cConfig.Common.LogLevel == nil { logLevel := log.InfoLevel cConfig.Common.LogLevel = &logLevel } + if flags.DebugLevel { + logLevel := log.DebugLevel + cConfig.Common.LogLevel = &logLevel + } if flags.TraceLevel { logLevel := log.TraceLevel cConfig.Common.LogLevel = &logLevel diff --git a/cmd/crowdsec/metrics.go b/cmd/crowdsec/metrics.go index 22a1faf9c..83d131cb1 100644 --- a/cmd/crowdsec/metrics.go +++ b/cmd/crowdsec/metrics.go @@ -67,11 +67,11 @@ func registerPrometheus(config *csconfig.PrometheusCfg) { return } if config.ListenAddr == "" { - log.Warningf("prometheus is enabled, but the listen address is empty, using '127.0.0.1'") + log.Warning("prometheus is enabled, but the listen address is empty, using '127.0.0.1'") config.ListenAddr = "127.0.0.1" } if config.ListenPort == 0 { - log.Warningf("prometheus is enabled, but the listen port is empty, using '6060'") + log.Warning("prometheus is enabled, but the listen port is empty, using '6060'") config.ListenPort = 6060 } diff --git a/cmd/crowdsec/pour.go b/cmd/crowdsec/pour.go index c5400f3df..aa5c7de02 100644 --- a/cmd/crowdsec/pour.go +++ b/cmd/crowdsec/pour.go @@ -31,7 +31,7 @@ func runPour(input chan types.Event, holders []leaky.BucketFactory, buckets *lea if err := z.UnmarshalText([]byte(parsed.MarshaledTime)); err != nil { log.Warningf("Failed to unmarshal time from event '%s' : %s", parsed.MarshaledTime, err) } else { - log.Warningf("Starting buckets garbage collection ...") + log.Warning("Starting buckets garbage collection ...") if err = leaky.GarbageCollectBuckets(*z, buckets); err != nil { return fmt.Errorf("failed to start bucket GC : %s", err) } diff --git a/cmd/crowdsec/serve.go b/cmd/crowdsec/serve.go index ab1e9304f..161a54875 100644 --- a/cmd/crowdsec/serve.go +++ b/cmd/crowdsec/serve.go @@ -191,7 +191,7 @@ func HandleSignals(cConfig *csconfig.Config) error { switch s { // kill -SIGHUP XXXX case syscall.SIGHUP: - log.Warningf("SIGHUP received, reloading") + log.Warning("SIGHUP received, reloading") if err := shutdown(s, cConfig); err != nil { exitChan <- errors.Wrap(err, "failed shutdown") break Loop @@ -202,7 +202,7 @@ func HandleSignals(cConfig *csconfig.Config) error { } // ctrl+C, kill -SIGINT XXXX, kill -SIGTERM XXXX case os.Interrupt, syscall.SIGTERM: - log.Warningf("SIGTERM received, shutting down") + log.Warning("SIGTERM received, shutting down") if err := shutdown(s, cConfig); err != nil { exitChan <- errors.Wrap(err, "failed shutdown") break Loop @@ -214,7 +214,7 @@ func HandleSignals(cConfig *csconfig.Config) error { err := <-exitChan if err == nil { - log.Warningf("Crowdsec service shutting down") + log.Warning("Crowdsec service shutting down") } return err } diff --git a/pkg/apiserver/apic.go b/pkg/apiserver/apic.go index f44e41348..6eb404839 100644 --- a/pkg/apiserver/apic.go +++ b/pkg/apiserver/apic.go @@ -475,7 +475,7 @@ func (a *apic) Pull() error { break } if !toldOnce { - log.Warningf("scenario list is empty, will not pull yet") + log.Warning("scenario list is empty, will not pull yet") toldOnce = true } time.Sleep(1 * time.Second) diff --git a/pkg/csconfig/api.go b/pkg/csconfig/api.go index 4751b5d7e..506583f7b 100644 --- a/pkg/csconfig/api.go +++ b/pkg/csconfig/api.go @@ -207,7 +207,7 @@ func (c *Config) LoadAPIServer() error { return err } } else { - log.Warningf("crowdsec local API is disabled") + log.Warning("crowdsec local API is disabled") c.DisableAPI = true } diff --git a/pkg/csconfig/crowdsec_service.go b/pkg/csconfig/crowdsec_service.go index 7498d2e06..8c78b10ae 100644 --- a/pkg/csconfig/crowdsec_service.go +++ b/pkg/csconfig/crowdsec_service.go @@ -39,7 +39,7 @@ func (c *Config) LoadCrowdsec() error { } if c.Crowdsec == nil { - log.Warningf("crowdsec agent is disabled") + log.Warning("crowdsec agent is disabled") c.DisableAgent = true return nil } @@ -68,7 +68,7 @@ func (c *Config) LoadCrowdsec() error { c.Crowdsec.AcquisitionFiles = append(c.Crowdsec.AcquisitionFiles, files...) } if c.Crowdsec.AcquisitionDirPath == "" && c.Crowdsec.AcquisitionFilePath == "" { - log.Warningf("no acquisition_path nor acquisition_dir") + log.Warning("no acquisition_path nor acquisition_dir") } if err := c.LoadSimulation(); err != nil { return errors.Wrap(err, "load error (simulation)") diff --git a/pkg/cwhub/helpers.go b/pkg/cwhub/helpers.go index 13eb90b2c..156eb5ab3 100644 --- a/pkg/cwhub/helpers.go +++ b/pkg/cwhub/helpers.go @@ -31,7 +31,7 @@ func chooseHubBranch() (string, error) { } if csVersion == "" { - log.Warningf("Crowdsec version is not set, using master branch for the hub") + log.Warning("Crowdsec version is not set, using master branch for the hub") return "master", nil } diff --git a/pkg/database/alerts.go b/pkg/database/alerts.go index d6a463036..cc4b2d77a 100644 --- a/pkg/database/alerts.go +++ b/pkg/database/alerts.go @@ -182,7 +182,7 @@ func (c *Client) UpdateCommunityBlocklist(alertItem *models.Alert) (int, int, in var start_ip, start_sfx, end_ip, end_sfx int64 var sz int if decisionItem.Duration == nil { - log.Warningf("nil duration in community decision") + log.Warning("nil duration in community decision") continue } duration, err := time.ParseDuration(*decisionItem.Duration) @@ -190,7 +190,7 @@ func (c *Client) UpdateCommunityBlocklist(alertItem *models.Alert) (int, int, in return 0, 0, 0, errors.Wrapf(ParseDurationFail, "decision duration '%v' : %s", decisionItem.Duration, err) } if decisionItem.Scope == nil { - log.Warningf("nil scope in community decision") + log.Warning("nil scope in community decision") continue } /*if the scope is IP or Range, convert the value to integers */ @@ -218,7 +218,7 @@ func (c *Client) UpdateCommunityBlocklist(alertItem *models.Alert) (int, int, in /*for bulk delete of duplicate decisions*/ if decisionItem.Value == nil { - log.Warningf("nil value in community decision") + log.Warning("nil value in community decision") continue } valueList = append(valueList, *decisionItem.Value) diff --git a/pkg/database/database.go b/pkg/database/database.go index 30d38c4a2..08f183630 100644 --- a/pkg/database/database.go +++ b/pkg/database/database.go @@ -150,7 +150,7 @@ func (c *Client) StartFlushScheduler(config *csconfig.FlushDBCfg) (*gocron.Sched config.AgentsGC.LoginPasswordDuration = &duration } if config.AgentsGC.Api != nil { - log.Warningf("agents auto-delete for API auth is not supported (use cert or login_password)") + log.Warning("agents auto-delete for API auth is not supported (use cert or login_password)") } } if config.BouncersGC != nil { @@ -169,7 +169,7 @@ func (c *Client) StartFlushScheduler(config *csconfig.FlushDBCfg) (*gocron.Sched config.BouncersGC.ApiDuration = &duration } if config.BouncersGC.LoginPassword != nil { - log.Warningf("bouncers auto-delete for login/password auth is not supported (use cert or api)") + log.Warning("bouncers auto-delete for login/password auth is not supported (use cert or api)") } } baJob, err := scheduler.Every(1).Minute().Do(c.FlushAgentsAndBouncers, config.AgentsGC, config.BouncersGC) diff --git a/pkg/leakybucket/buckets_test.go b/pkg/leakybucket/buckets_test.go index 5875a7fc1..fb4934c6f 100644 --- a/pkg/leakybucket/buckets_test.go +++ b/pkg/leakybucket/buckets_test.go @@ -69,7 +69,7 @@ func TestBucket(t *testing.T) { func watchTomb(tomb *tomb.Tomb) { for { if tomb.Alive() == false { - log.Warningf("Tomb is dead") + log.Warning("Tomb is dead") break } time.Sleep(100 * time.Millisecond) @@ -158,7 +158,7 @@ func testFile(t *testing.T, file string, bs string, holders []BucketFactory, res t.Errorf("Failed to load testfile '%s' yaml error : %v", file, err) return false } - log.Warningf("end of test file") + log.Warning("end of test file") } var latest_ts time.Time for _, in := range tf.Lines { @@ -181,10 +181,10 @@ func testFile(t *testing.T, file string, bs string, holders []BucketFactory, res t.Fatalf("Failed to pour : %s", err) } if !ok { - log.Warningf("Event wasn't poured") + log.Warning("Event wasn't poured") } } - log.Warningf("Done pouring !") + log.Warning("Done pouring !") time.Sleep(1 * time.Second) @@ -194,7 +194,7 @@ POLL_AGAIN: for fails < 2 { select { case ret := <-response: - log.Warningf("got one result") + log.Warning("got one result") results = append(results, ret) if ret.Overflow.Reprocess { log.Errorf("Overflow being reprocessed.") @@ -203,13 +203,13 @@ POLL_AGAIN: t.Fatalf("Failed to pour : %s", err) } if !ok { - log.Warningf("Event wasn't poured") + log.Warning("Event wasn't poured") } goto POLL_AGAIN } fails = 0 default: - log.Warningf("no more results") + log.Warning("no more results") time.Sleep(1 * time.Second) fails += 1 } @@ -223,7 +223,7 @@ POLL_AGAIN: for { if len(tf.Results) == 0 && len(results) == 0 { - log.Warningf("Test is successful") + log.Warning("Test is successful") if dump { if tmpFile, err = DumpBucketsStateAt(latest_ts, ".", buckets); err != nil { t.Fatalf("Failed dumping bucket state : %s", err) @@ -305,6 +305,6 @@ POLL_AGAIN: log.Errorf("we expected: %s", spew.Sdump(tf.Results)) return false } - log.Warningf("entry valid at end of loop") + log.Warning("entry valid at end of loop") } } diff --git a/pkg/leakybucket/manager_load.go b/pkg/leakybucket/manager_load.go index c7b23c872..c648cda75 100644 --- a/pkg/leakybucket/manager_load.go +++ b/pkg/leakybucket/manager_load.go @@ -266,7 +266,7 @@ func LoadBucket(bucketFactory *BucketFactory, tomb *tomb.Tomb) error { } if bucketFactory.Filter == "" { - bucketFactory.logger.Warningf("Bucket without filter, abort.") + bucketFactory.logger.Warning("Bucket without filter, abort.") return fmt.Errorf("bucket without filter directive") } bucketFactory.RunTimeFilter, err = expr.Compile(bucketFactory.Filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}}))) diff --git a/pkg/leakybucket/overflows.go b/pkg/leakybucket/overflows.go index e7c98f623..3b43cbe54 100644 --- a/pkg/leakybucket/overflows.go +++ b/pkg/leakybucket/overflows.go @@ -198,7 +198,7 @@ func EventsFromQueue(queue *Queue) []*models.Event { *ovflwEvent.Timestamp = string(raw) } } else { - log.Warningf("Event has no parsed time, no runtime timestamp") + log.Warning("Event has no parsed time, no runtime timestamp") } events = append(events, &ovflwEvent) diff --git a/pkg/parser/enrich_date.go b/pkg/parser/enrich_date.go index 25d81e893..6fe1b12f9 100644 --- a/pkg/parser/enrich_date.go +++ b/pkg/parser/enrich_date.go @@ -47,7 +47,7 @@ func GenDateParse(date string) (string, time.Time) { now := time.Now().UTC() retstr, err := now.MarshalText() if err != nil { - log.Warningf("Failed marshaling current time") + log.Warning("Failed marshaling current time") return "", time.Time{} } return string(retstr), now diff --git a/pkg/parser/node.go b/pkg/parser/node.go index 851520a64..1b0282bde 100644 --- a/pkg/parser/node.go +++ b/pkg/parser/node.go @@ -193,7 +193,7 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx, expressionEnv map[stri output, err := expr.Run(e.Filter, cachedExprEnv) if err != nil { clog.Warningf("failed to run whitelist expr : %v", err) - clog.Debugf("Event leaving node : ko") + clog.Debug("Event leaving node : ko") return false, nil } switch out := output.(type) { diff --git a/pkg/parser/parsing_test.go b/pkg/parser/parsing_test.go index 0f3777258..ba87438b7 100644 --- a/pkg/parser/parsing_test.go +++ b/pkg/parser/parsing_test.go @@ -334,7 +334,7 @@ reCheck: } func testFile(testSet []TestFile, pctx UnixParserCtx, nodes []Node) bool { - log.Warningf("Going to process one test set") + log.Warning("Going to process one test set") for _, tf := range testSet { //func testSubSet(testSet TestFile, pctx UnixParserCtx, nodes []Node) (bool, error) { testOk, err := testSubSet(tf, pctx, nodes)