Skip to content

Commit

Permalink
config: Add log configuration items to the config file
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSupeng committed Jun 29, 2021
1 parent b7f6780 commit e8b9455
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
7 changes: 5 additions & 2 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ func runEServer(cmd *cobra.Command, args []string) error {
}

cancel := initCmd(cmd, &logutil.Config{
File: conf.LogFile,
Level: conf.LogLevel,
File: conf.LogFile,
Level: conf.LogLevel,
FileMaxSize: conf.Log.File.MaxSize,
FileMaxDays: conf.Log.File.MaxDays,
FileMaxBackups: conf.Log.File.MaxBackups,
})
defer cancel()
tz, err := util.GetTimezone(conf.TZ)
Expand Down
27 changes: 27 additions & 0 deletions cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ func (s *serverSuite) TestLoadAndVerifyServerConfig(c *check.C) {
AdvertiseAddr: "127.5.5.1:7777",
LogFile: "/root/cdc.log",
LogLevel: "debug",
Log: &config.LogConfig{
File:&config.LogFileConfig{
MaxSize: 300,
MaxDays: 0,
MaxBackups: 0,
},
},
DataDir: dataDir,
GcTTL: 10,
TZ: "UTC",
Expand Down Expand Up @@ -165,6 +172,7 @@ advertise-addr = "127.0.0.1:1111"
log-file = "/root/cdc1.log"
log-level = "warn"
data-dir = "%+v"
gc-ttl = 500
tz = "US"
Expand All @@ -173,6 +181,11 @@ capture-session-ttl = 10
owner-flush-interval = "600ms"
processor-flush-interval = "600ms"
[log.file]
max-size = 200
max-days = 1
max-backups = 1
[sorter]
chunk-size-limit = 10000000
max-memory-consumption = 2000000
Expand All @@ -193,6 +206,13 @@ sort-dir = "/tmp/just_a_test"
AdvertiseAddr: "127.0.0.1:1111",
LogFile: "/root/cdc1.log",
LogLevel: "warn",
Log: &config.LogConfig{
File:&config.LogFileConfig{
MaxSize: 200,
MaxDays: 1,
MaxBackups: 1,
},
},
DataDir: dataDir,
GcTTL: 500,
TZ: "US",
Expand Down Expand Up @@ -250,6 +270,13 @@ cert-allowed-cn = ["dd","ee"]
AdvertiseAddr: "127.0.0.1:1111",
LogFile: "/root/cdc.log",
LogLevel: "debug",
Log: &config.LogConfig{
File:&config.LogFileConfig{
MaxSize: 200,
MaxDays: 1,
MaxBackups: 1,
},
},
DataDir: dataDir,
GcTTL: 10,
TZ: "UTC",
Expand Down
10 changes: 10 additions & 0 deletions cmd/ticdc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ log-level = "info"
# the time zone of TiCDC cluster, default: "System"
# tz = "System"

[log.file]
# Max log file size in MB (upper limit to 4096MB).
max-size = 300

# Max log file keep days. No clean up by default.
max-days = 0

# Maximum number of old log files to retain. No clean up by default.
max-backups = 0

[security]
# ca-path = ""
# cert-path = ""
Expand Down
26 changes: 23 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,29 @@ func GetDefaultReplicaConfig() *ReplicaConfig {
// SecurityConfig represents security config for server
type SecurityConfig = security.Credential

// LogConfig represents log config for server
type LogFileConfig struct {
MaxSize int `toml:"max-size" json:"max-size"`
MaxDays int `toml:"max-days" json:"max-days"`
MaxBackups int `toml:"max-backups" json:"max-backups"`
}

type LogConfig struct {
File *LogFileConfig `toml:"file" json:"file"`
}

var defaultServerConfig = &ServerConfig{
Addr: "127.0.0.1:8300",
AdvertiseAddr: "",
LogFile: "",
LogLevel: "info",
Log: &LogConfig{
File:&LogFileConfig{
MaxSize: 300,
MaxDays: 0,
MaxBackups: 0,
},
},
DataDir: "",
GcTTL: 24 * 60 * 60, // 24H
TZ: "System",
Expand Down Expand Up @@ -183,9 +201,11 @@ type ServerConfig struct {
Addr string `toml:"addr" json:"addr"`
AdvertiseAddr string `toml:"advertise-addr" json:"advertise-addr"`

LogFile string `toml:"log-file" json:"log-file"`
LogLevel string `toml:"log-level" json:"log-level"`
DataDir string `toml:"data-dir" json:"data-dir"`
LogFile string `toml:"log-file" json:"log-file"`
LogLevel string `toml:"log-level" json:"log-level"`
Log *LogConfig `toml:"log" json:"log"`

DataDir string `toml:"data-dir" json:"data-dir"`

GcTTL int64 `toml:"gc-ttl" json:"gc-ttl"`
TZ string `toml:"tz" json:"tz"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ var _ = check.Suite(&serverConfigSuite{})

func (s *serverConfigSuite) TestMarshal(c *check.C) {
defer testleak.AfterTest(c)()
rawConfig := `{"addr":"192.155.22.33:8887","advertise-addr":"","log-file":"","log-level":"info","data-dir":"","gc-ttl":86400,"tz":"System","capture-session-ttl":10,"owner-flush-interval":200000000,"processor-flush-interval":100000000,"sorter":{"num-concurrent-worker":4,"chunk-size-limit":999,"max-memory-percentage":30,"max-memory-consumption":17179869184,"num-workerpool-goroutine":16,"sort-dir":"/tmp/sorter"},"security":{"ca-path":"","cert-path":"","key-path":"","cert-allowed-cn":null},"per-table-memory-quota":20971520,"kv-client":{"worker-concurrent":8,"worker-pool-size":0,"region-scan-limit":40}}`
rawConfig := `{"addr":"192.155.22.33:8887","advertise-addr":"","log-file":"","log-level":"info","log":{"file":{"max-size":300,"max-days":0,"max-backups":0}},"data-dir":"","gc-ttl":86400,"tz":"System","capture-session-ttl":10,"owner-flush-interval":200000000,"processor-flush-interval":100000000,"sorter":{"num-concurrent-worker":4,"chunk-size-limit":999,"max-memory-percentage":30,"max-memory-consumption":17179869184,"num-workerpool-goroutine":16,"sort-dir":"/tmp/sorter"},"security":{"ca-path":"","cert-path":"","key-path":"","cert-allowed-cn":null},"per-table-memory-quota":20971520,"kv-client":{"worker-concurrent":8,"worker-pool-size":0,"region-scan-limit":40}}`

conf := GetDefaultServerConfig()
conf.Addr = "192.155.22.33:8887"
Expand Down

0 comments on commit e8b9455

Please sign in to comment.