Skip to content

Commit

Permalink
mod log cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
sheyanjie-qq committed Sep 21, 2024
1 parent 5a70af6 commit e4b79bd
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
11 changes: 9 additions & 2 deletions config/taoskeeper.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
9 changes: 7 additions & 2 deletions infrastructure/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`)
Expand All @@ -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")
Expand All @@ -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")

Expand Down
1 change: 1 addition & 0 deletions infrastructure/config/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Log struct {
RotationCount uint
RotationTime time.Duration
RotationSize uint
KeepDays uint
Compress bool
ReservedDiskSize uint
}
2 changes: 2 additions & 0 deletions infrastructure/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e4b79bd

Please sign in to comment.