From d348f12a0e7f9a6e4d1193324a0d6446fa943d00 Mon Sep 17 00:00:00 2001 From: Jeremy Lin Date: Wed, 22 Jul 2020 21:50:49 -0700 Subject: [PATCH 1/2] Add config option for log timestamp format --- .env.template | 4 ++++ src/config.rs | 2 ++ src/main.rs | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.env.template b/.env.template index 8c0a1c11..01ad4355 100644 --- a/.env.template +++ b/.env.template @@ -44,6 +44,10 @@ ## Enable extended logging, which shows timestamps and targets in the logs # EXTENDED_LOGGING=true +## Timestamp format used in extended logging. +## Format specifiers: https://docs.rs/chrono/latest/chrono/format/strftime +# LOG_TIMESTAMP_FORMAT="%Y-%m-%d %H:%M:%S" + ## Logging to file ## It's recommended to also set 'ROCKET_CLI_COLORS=off' # LOG_FILE=/path/to/log diff --git a/src/config.rs b/src/config.rs index 8c6126fd..d8282735 100644 --- a/src/config.rs +++ b/src/config.rs @@ -329,6 +329,8 @@ make_config! { reload_templates: bool, true, def, false; /// Enable extended logging extended_logging: bool, false, def, true; + /// Log timestamp format + log_timestamp_format: String, true, def, "%Y-%m-%d %H:%M:%S".to_string(); /// Enable the log to output to Syslog use_syslog: bool, false, def, false; /// Log file path diff --git a/src/main.rs b/src/main.rs index 4c7a6187..7f32a727 100644 --- a/src/main.rs +++ b/src/main.rs @@ -130,8 +130,8 @@ fn init_logging(level: log::LevelFilter) -> Result<(), fern::InitError> { if CONFIG.extended_logging() { logger = logger.format(|out, message, record| { out.finish(format_args!( - "{}[{}][{}] {}", - chrono::Local::now().format("[%Y-%m-%d %H:%M:%S]"), + "[{}][{}][{}] {}", + chrono::Local::now().format(&CONFIG.log_timestamp_format()), record.target(), record.level(), message From 071a3b2a32e1d9cb31b3b2e38442fd33d6512639 Mon Sep 17 00:00:00 2001 From: Jeremy Lin Date: Thu, 23 Jul 2020 14:19:51 -0700 Subject: [PATCH 2/2] Log timestamps with milliseconds by default --- .env.template | 2 +- src/config.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.env.template b/.env.template index 01ad4355..4cd3ed25 100644 --- a/.env.template +++ b/.env.template @@ -46,7 +46,7 @@ ## Timestamp format used in extended logging. ## Format specifiers: https://docs.rs/chrono/latest/chrono/format/strftime -# LOG_TIMESTAMP_FORMAT="%Y-%m-%d %H:%M:%S" +# LOG_TIMESTAMP_FORMAT="%Y-%m-%d %H:%M:%S.%3f" ## Logging to file ## It's recommended to also set 'ROCKET_CLI_COLORS=off' diff --git a/src/config.rs b/src/config.rs index d8282735..1192f75d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -330,7 +330,7 @@ make_config! { /// Enable extended logging extended_logging: bool, false, def, true; /// Log timestamp format - log_timestamp_format: String, true, def, "%Y-%m-%d %H:%M:%S".to_string(); + log_timestamp_format: String, true, def, "%Y-%m-%d %H:%M:%S.%3f".to_string(); /// Enable the log to output to Syslog use_syslog: bool, false, def, false; /// Log file path