diff --git a/cmd/tikv-server/src/main.rs b/cmd/tikv-server/src/main.rs index de058b545e0..9596ea29984 100644 --- a/cmd/tikv-server/src/main.rs +++ b/cmd/tikv-server/src/main.rs @@ -178,6 +178,7 @@ fn main() { }); server::setup::overwrite_config_with_cmd_args(&mut config, &matches); + config.logger_compatible_adjust(); if is_config_check { validate_and_persist_config(&mut config, false); diff --git a/src/config.rs b/src/config.rs index a87531d071e..482d103fbc0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2550,7 +2550,7 @@ impl Default for TiKvConfig { log_level: slog::Level::Info, log_file: "".to_owned(), log_format: LogFormat::Text, - log_rotation_timespan: ReadableDuration::hours(24), + log_rotation_timespan: ReadableDuration::hours(0), log_rotation_size: ReadableSize::mb(300), slow_log_file: "".to_owned(), slow_log_threshold: ReadableDuration::secs(1), @@ -2780,6 +2780,59 @@ impl TiKvConfig { Ok(()) } + // As the init of `logger` is very early, this adjust needs to be separated and called + // immediately after parsing the command line. + pub fn logger_compatible_adjust(&mut self) { + let default_tikv_cfg = TiKvConfig::default(); + let default_log_cfg = LogConfig::default(); + if self.log_level != default_tikv_cfg.log_level { + println!("deprecated configuration, log-level has been moved to log.level"); + if self.log.level == default_log_cfg.level { + println!("override log.level with log-level, {:?}", self.log_level); + self.log.level = self.log_level; + } + self.log_level = default_tikv_cfg.log_level; + } + if self.log_file != default_tikv_cfg.log_file { + println!("deprecated configuration, log-file has been moved to log.file.filename"); + if self.log.file.filename == default_log_cfg.file.filename { + println!( + "override log.file.filename with log-file, {:?}", + self.log_file + ); + self.log.file.filename = self.log_file.clone(); + } + self.log_file = default_tikv_cfg.log_file; + } + if self.log_format != default_tikv_cfg.log_format { + println!("deprecated configuration, log-format has been moved to log.format"); + if self.log.format == default_log_cfg.format { + println!("override log.format with log-format, {:?}", self.log_format); + self.log.format = self.log_format; + } + self.log_format = default_tikv_cfg.log_format; + } + if self.log_rotation_timespan.as_secs() > 0 { + println!( + "deprecated configuration, log-rotation-timespan is no longer used and ignored." + ); + } + if self.log_rotation_size != default_tikv_cfg.log_rotation_size { + println!( + "deprecated configuration, \ + log-ratation-size has been moved to log.file.max-size" + ); + if self.log.file.max_size == default_log_cfg.file.max_size { + println!( + "override log.file.max_size with log-rotation-size, {:?}", + self.log_rotation_size + ); + self.log.file.max_size = self.log_rotation_size.as_mb(); + } + self.log_rotation_size = default_tikv_cfg.log_rotation_size; + } + } + pub fn compatible_adjust(&mut self) { let default_raft_store = RaftstoreConfig::default(); let default_coprocessor = CopConfig::default(); @@ -2890,56 +2943,6 @@ impl TiKvConfig { } self.readpool.adjust_use_unified_pool(); - - let default_tikv_cfg = TiKvConfig::default(); - let default_log_cfg = LogConfig::default(); - if self.log_level != default_tikv_cfg.log_level { - warn!("deprecated configuration, log-level has been moved to log.level"); - if self.log.level == default_log_cfg.level { - warn!("override log.level with log-level, {:?}", self.log_level); - self.log.level = self.log_level; - } - self.log_level = default_tikv_cfg.log_level; - } - if self.log_file != default_tikv_cfg.log_file { - warn!("deprecated configuration, log-file has been moved to log.file.filename"); - if self.log.file.filename == default_log_cfg.file.filename { - warn!( - "override log.file.filename with log-file, {:?}", - self.log_file - ); - self.log.file.filename = self.log_file.clone(); - } - self.log_file = default_tikv_cfg.log_file; - } - if self.log_format != default_tikv_cfg.log_format { - warn!("deprecated configuration, log-format has been moved to log.format"); - if self.log.format == default_log_cfg.format { - warn!("override log.format with log-format, {:?}", self.log_format); - self.log.format = self.log_format; - } - self.log_format = default_tikv_cfg.log_format; - } - if self.log_rotation_timespan.as_secs() > 0 { - warn!( - "deprecated configuration, {} is no longer used and ignored.", - "log-rotation-timespan", - ); - } - if self.log_rotation_size != default_tikv_cfg.log_rotation_size { - warn!( - "deprecated configuration, \ - log-ratation-size has been moved to log.file.max-size" - ); - if self.log.file.max_size == default_log_cfg.file.max_size { - warn!( - "override log.file.max_size with log-rotation-size, {:?}", - self.log_rotation_size - ); - self.log.file.max_size = self.log_rotation_size.as_mb(); - } - self.log_rotation_size = default_tikv_cfg.log_rotation_size; - } } pub fn check_critical_cfg_with(&self, last_cfg: &Self) -> Result<(), String> { diff --git a/tests/integrations/config/mod.rs b/tests/integrations/config/mod.rs index 8af03fbbb78..f69c437ca91 100644 --- a/tests/integrations/config/mod.rs +++ b/tests/integrations/config/mod.rs @@ -59,6 +59,7 @@ fn read_file_in_project_dir(path: &str) -> String { #[test] fn test_serde_custom_tikv_config() { let mut value = TiKvConfig::default(); + value.log_rotation_timespan = ReadableDuration::days(1); value.log.level = Level::Critical; value.log.file.filename = "foo".to_owned(); value.log.format = LogFormat::Json; @@ -849,7 +850,7 @@ fn test_log_backward_compatible() { assert_eq!(cfg.log.file.filename, ""); assert_eq!(cfg.log.format, LogFormat::Text); assert_eq!(cfg.log.file.max_size, 300); - cfg.compatible_adjust(); + cfg.logger_compatible_adjust(); assert_eq!(cfg.log.level, slog::Level::Critical); assert_eq!(cfg.log.file.filename, "foo"); assert_eq!(cfg.log.format, LogFormat::Json);