mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
feat: Add support to enable FullTimeStamp in logging (#15127)
* Add support to enable FullTimeStamp in logging Signed-off-by: skalinov <skalinov@tradingview.com> * fix: Fix go linter file exist issue Signed-off-by: skalinov <skalinov@tradingview.com> * fix: Remove --skip-pkg-cache Signed-off-by: skalinov <skalinov@tradingview.com> * Update util/log/logrus_test.go Use custom set env for prevent linter to be failed Signed-off-by: pasha-codefresh <pavel@codefresh.io> * Update common/common.go Signed-off-by: Dan Garfield <dan@codefresh.io> * Update util/log/logrus_test.go Signed-off-by: pasha-codefresh <pavel@codefresh.io> * Update util/log/logrus_test.go remove os import Signed-off-by: pasha-codefresh <pavel@codefresh.io> * Update util/log/logrus_test.go sort dependencies Signed-off-by: pasha-codefresh <pavel@codefresh.io> * fix formatting Signed-off-by: pashakostohrys <pavel@codefresh.io> --------- Signed-off-by: pasha-codefresh <pavel@codefresh.io> Signed-off-by: Dan Garfield <dan@codefresh.io> Signed-off-by: pashakostohrys <pavel@codefresh.io> Co-authored-by: skalinov <skalinov@tradingview.com> Co-authored-by: pasha-codefresh <pavel@codefresh.io> Co-authored-by: Dan Garfield <dan@codefresh.io>
This commit is contained in:
@@ -242,6 +242,8 @@ const (
|
||||
EnvLogFormat = "ARGOCD_LOG_FORMAT"
|
||||
// EnvLogLevel log level that is defined by `--loglevel` option
|
||||
EnvLogLevel = "ARGOCD_LOG_LEVEL"
|
||||
// EnvLogFormatEnableFullTimestamp enables the FullTimestamp option in logs
|
||||
EnvLogFormatEnableFullTimestamp = "ARGOCD_LOG_FORMAT_ENABLE_FULL_TIMESTAMP"
|
||||
// EnvMaxCookieNumber max number of chunks a cookie can be broken into
|
||||
EnvMaxCookieNumber = "ARGOCD_MAX_COOKIE_NUMBER"
|
||||
// EnvPluginSockFilePath allows to override the pluginSockFilePath for repo server and cmp server
|
||||
|
||||
@@ -38,13 +38,14 @@ func CreateFormatter(logFormat string) logrus.Formatter {
|
||||
case JsonFormat:
|
||||
formatType = &logrus.JSONFormatter{}
|
||||
case TextFormat:
|
||||
if os.Getenv("FORCE_LOG_COLORS") == "1" {
|
||||
formatType = &logrus.TextFormatter{ForceColors: true}
|
||||
} else {
|
||||
formatType = &logrus.TextFormatter{}
|
||||
formatType = &logrus.TextFormatter{
|
||||
ForceColors: checkForceLogColors(),
|
||||
FullTimestamp: checkEnableFullTimestamp(),
|
||||
}
|
||||
default:
|
||||
formatType = &logrus.TextFormatter{}
|
||||
formatType = &logrus.TextFormatter{
|
||||
FullTimestamp: checkEnableFullTimestamp(),
|
||||
}
|
||||
}
|
||||
|
||||
return formatType
|
||||
@@ -57,3 +58,11 @@ func createLogLevel() logrus.Level {
|
||||
}
|
||||
return level
|
||||
}
|
||||
|
||||
func checkForceLogColors() bool {
|
||||
return strings.ToLower(os.Getenv("FORCE_LOG_COLORS")) == "1"
|
||||
}
|
||||
|
||||
func checkEnableFullTimestamp() bool {
|
||||
return strings.ToLower(os.Getenv(common.EnvLogFormatEnableFullTimestamp)) == "1"
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/argoproj/argo-cd/v2/common"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -23,6 +25,16 @@ func TestCreateFormatter(t *testing.T) {
|
||||
result := CreateFormatter("text")
|
||||
assert.Equal(t, &logrus.TextFormatter{}, result)
|
||||
})
|
||||
t.Run(fmt.Sprintf("%s == 1", common.EnvLogFormatEnableFullTimestamp), func(t *testing.T) {
|
||||
t.Setenv(common.EnvLogFormatEnableFullTimestamp, "1")
|
||||
result := CreateFormatter("text")
|
||||
assert.Equal(t, &logrus.TextFormatter{FullTimestamp: true}, result)
|
||||
})
|
||||
t.Run(fmt.Sprintf("%s != 1", common.EnvLogFormatEnableFullTimestamp), func(t *testing.T) {
|
||||
t.Setenv(common.EnvLogFormatEnableFullTimestamp, "0")
|
||||
result := CreateFormatter("text")
|
||||
assert.Equal(t, &logrus.TextFormatter{}, result)
|
||||
})
|
||||
})
|
||||
t.Run("log format is not json or text", func(t *testing.T) {
|
||||
result := CreateFormatter("xml")
|
||||
|
||||
Reference in New Issue
Block a user