Skip to content

Commit

Permalink
logging: full timestamp with timezone in crowdsec.log (#2707)
Browse files Browse the repository at this point in the history
RFC3339 = "2006-01-02T15:04:05Z07:00" (same as /var/log/syslog)
  • Loading branch information
mmetc committed Jan 8, 2024
1 parent 58f91dc commit f306d59
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions cmd/crowdsec-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package main

import (
"os"
"slices"
"time"

"github.com/fatih/color"
cc "github.com/ivanpirog/coloredcobra"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"slices"

"github.com/crowdsecurity/crowdsec/pkg/csconfig"
"github.com/crowdsecurity/crowdsec/pkg/database"
Expand Down Expand Up @@ -107,7 +108,7 @@ var NoNeedConfig = []string{

func main() {
// set the formatter asap and worry about level later
logFormatter := &log.TextFormatter{TimestampFormat: "2006-01-02 15:04:05", FullTimestamp: true}
logFormatter := &log.TextFormatter{TimestampFormat: time.RFC3339, FullTimestamp: true}
log.SetFormatter(logFormatter)

if err := fflag.RegisterAllFeatures(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func SetDefaultLoggerConfig(cfgMode string, cfgFolder string, cfgLevel log.Level
}
logLevel = cfgLevel
log.SetLevel(logLevel)
logFormatter = &log.TextFormatter{TimestampFormat: "2006-01-02 15:04:05", FullTimestamp: true, ForceColors: forceColors}
logFormatter = &log.TextFormatter{TimestampFormat: time.RFC3339, FullTimestamp: true, ForceColors: forceColors}
log.SetFormatter(logFormatter)
return nil
}
Expand Down

0 comments on commit f306d59

Please sign in to comment.