From e4b79bd5070822cb9062b64b6340cc30fa5ff6e0 Mon Sep 17 00:00:00 2001 From: sheyanjie-qq <249478495@qq.com> Date: Sat, 21 Sep 2024 10:11:26 +0800 Subject: [PATCH] mod log cfg --- config/taoskeeper.toml | 11 +++++++++-- go.mod | 2 +- go.sum | 4 ++-- infrastructure/config/config.go | 9 +++++++-- infrastructure/config/log.go | 1 + infrastructure/log/log.go | 2 ++ 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/config/taoskeeper.toml b/config/taoskeeper.toml index 1afcc50..89847db 100644 --- a/config/taoskeeper.toml +++ b/config/taoskeeper.toml @@ -38,9 +38,16 @@ cachemodel = "both" incgroup = false [log] +# The directory where log files are stored. +# path = "/var/log/taos" level = "info" +# Number of log file rotations before deletion. rotationCount = 30 -rotationTime = "24h" +# The number of days to retain log files. +keepDays = 30 +# The maximum size of a log file before rotation. rotationSize = "1GB" -compress = true +# If set to true, log files will be compressed. +compress = false +# Minimum disk space to reserve. Log files will not be written if disk space falls below this limit. reservedDiskSize = "1GB" diff --git a/go.mod b/go.mod index 05668e3..5adff6b 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/spf13/viper v1.12.0 github.com/stretchr/testify v1.9.0 github.com/taosdata/driver-go/v3 v3.5.7 - github.com/taosdata/file-rotatelogs/v2 v2.4.2-0.20240902095728-4d2fc56eb8f5 + github.com/taosdata/file-rotatelogs/v2 v2.5.2 github.com/taosdata/go-utils v0.0.0-20211022070036-018cc5f2432a ) diff --git a/go.sum b/go.sum index d021acb..cd1dd7d 100644 --- a/go.sum +++ b/go.sum @@ -372,8 +372,8 @@ github.com/subosito/gotenv v1.3.0/go.mod h1:YzJjq/33h7nrwdY+iHMhEOEEbW0ovIz0tB6t github.com/taosdata/driver-go/v2 v2.0.1-0.20211018081904-0a2a3ef6c829/go.mod h1:W7pu74rSvDmGjJPO6fzp+GCtwOelrMgXEhPD0aQJ1xw= github.com/taosdata/driver-go/v3 v3.5.7 h1:Oggrq/RTqzu5ICldOMqRXHWhIpDj1p62rzhSWvQTNvc= github.com/taosdata/driver-go/v3 v3.5.7/go.mod h1:H2vo/At+rOPY1aMzUV9P49SVX7NlXb3LAbKw+MCLrmU= -github.com/taosdata/file-rotatelogs/v2 v2.4.2-0.20240902095728-4d2fc56eb8f5 h1:XwN7NtjxSlWp2SfQPYl2pfHb0L/MgPph+YspumKRChY= -github.com/taosdata/file-rotatelogs/v2 v2.4.2-0.20240902095728-4d2fc56eb8f5/go.mod h1:Qm99Lh0iMZouGgyy++JgTqKvP5FQw1ruR5jkWF7e1n0= +github.com/taosdata/file-rotatelogs/v2 v2.5.2 h1:6ryjwDdKqQtWrkVq9OKj4gvMING/f+fDluMAAe2DIXQ= +github.com/taosdata/file-rotatelogs/v2 v2.5.2/go.mod h1:Qm99Lh0iMZouGgyy++JgTqKvP5FQw1ruR5jkWF7e1n0= github.com/taosdata/go-utils v0.0.0-20211022070036-018cc5f2432a h1:WGFREiuYBrTXTS9GVQQpDvVgGRyByfo0V5//o7tv/ho= github.com/taosdata/go-utils v0.0.0-20211022070036-018cc5f2432a/go.mod h1:hlvGgM/HN3AqWMajvMQe80qoLNJ4KIxs8YOVqEqnxUo= github.com/tidwall/gjson v1.9.1/go.mod h1:jydLKE7s8J0+1/5jC4eXcuFlzKizGrCKvLmBVX/5oXc= diff --git a/infrastructure/config/config.go b/infrastructure/config/config.go index f55984b..9cb0ab6 100644 --- a/infrastructure/config/config.go +++ b/infrastructure/config/config.go @@ -246,6 +246,10 @@ func initLog() { _ = viper.BindEnv("log.rotationCount", "TAOS_KEEPER_LOG_ROTATION_COUNT") pflag.Uint("log.rotationCount", 5, `log rotation count. Env "TAOS_KEEPER_LOG_ROTATION_COUNT"`) + viper.SetDefault("log.keepDays", 30) + _ = viper.BindEnv("log.keepDays", "TAOS_KEEPER_LOG_KEEP_DAYS") + pflag.Uint("log.keepDays", 30, `log retention days, must be a positive integer. Env "TAOS_KEEPER_LOG_KEEP_DAYS"`) + viper.SetDefault("log.rotationTime", time.Hour*24) _ = viper.BindEnv("log.rotationTime", "TAOS_KEEPER_LOG_ROTATION_TIME") pflag.Duration("log.rotationTime", time.Hour*24, `deprecated: log rotation time always 24 hours. Env "TAOS_KEEPER_LOG_ROTATION_TIME"`) @@ -254,9 +258,9 @@ func initLog() { _ = viper.BindEnv("log.rotationSize", "TAOS_KEEPER_LOG_ROTATION_SIZE") pflag.String("log.rotationSize", "1GB", `log rotation size(KB MB GB), must be a positive integer. Env "TAOS_KEEPER_LOG_ROTATION_SIZE"`) - viper.SetDefault("log.compress", true) + viper.SetDefault("log.compress", false) _ = viper.BindEnv("log.compress", "TAOS_KEEPER_LOG_COMPRESS") - pflag.Bool("log.compress", true, `whether to compress old log. Env "TAOS_KEEPER_LOG_COMPRESS"`) + pflag.Bool("log.compress", false, `whether to compress old log. Env "TAOS_KEEPER_LOG_COMPRESS"`) viper.SetDefault("log.reservedDiskSize", "1GB") _ = viper.BindEnv("log.reservedDiskSize", "TAOS_KEEPER_LOG_RESERVED_DISK_SIZE") @@ -270,6 +274,7 @@ func (l *Log) SetValue() { l.RotationCount = viper.GetUint("log.rotationCount") l.RotationTime = viper.GetDuration("log.rotationTime") l.RotationSize = viper.GetSizeInBytes("log.rotationSize") + l.KeepDays = viper.GetUint("log.keepDays") l.Compress = viper.GetBool("log.compress") l.ReservedDiskSize = viper.GetSizeInBytes("log.reservedDiskSize") diff --git a/infrastructure/config/log.go b/infrastructure/config/log.go index 5eaf795..e317a1d 100644 --- a/infrastructure/config/log.go +++ b/infrastructure/config/log.go @@ -10,6 +10,7 @@ type Log struct { RotationCount uint RotationTime time.Duration RotationSize uint + KeepDays uint Compress bool ReservedDiskSize uint } diff --git a/infrastructure/log/log.go b/infrastructure/log/log.go index 407bcb9..0a54e99 100644 --- a/infrastructure/log/log.go +++ b/infrastructure/log/log.go @@ -126,6 +126,8 @@ func ConfigLog() { rotatelogs.WithRotateGlobPattern(filepath.Join(config.Conf.Log.Path, fmt.Sprintf("%skeeper_%d_*.log*", version.CUS_PROMPT, config.Conf.InstanceID))), rotatelogs.WithCompress(config.Conf.Log.Compress), rotatelogs.WithCleanLockFile(filepath.Join(config.Conf.Log.Path, fmt.Sprintf(".%skeeper_%d_rotate_lock", version.CUS_PROMPT, config.Conf.InstanceID))), + rotatelogs.ForceNewFile(), + rotatelogs.WithMaxAge(time.Hour*24*time.Duration(config.Conf.Log.KeepDays)), ) if err != nil { panic(err)