Skip to content

Commit

Permalink
refactor: shorten log time format (jtroo#1011)
Browse files Browse the repository at this point in the history
Shorten logged time format.

`time` crate needs to be added to Cargo.toml excplicitly, otherwise
`format_description` gives an error.

Before vs after:
```
2024-05-04T17:07:38.975459272+02:00 [INFO] config file is valid
17:07:59.8868 [INFO] config file is valid
```
  • Loading branch information
rszyma authored May 4, 2024
1 parent 0f98920 commit 0345e2d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ radix_trie = "0.2"
rustc-hash = "1.1.0"
simplelog = "0.12.0"
serde_json = { version = "1", features = ["std"], default_features = false, optional = true }
time = "0.3.36"

# kanata-keyberon = "0.161.0"
# kanata-parser = "0.161.0"
Expand Down
8 changes: 5 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use clap::Parser;
use kanata_parser::cfg;
use kanata_state_machine::*;
use log::info;
use simplelog::*;

use simplelog::{format_description, *};
use std::path::PathBuf;

#[cfg(test)]
Expand Down Expand Up @@ -117,7 +116,10 @@ fn cli_init() -> Result<ValidatedArgs> {
if let Err(e) = log_cfg.set_time_offset_to_local() {
eprintln!("WARNING: could not set log TZ to local: {e:?}");
};
log_cfg.set_time_format_rfc3339();
log_cfg.set_time_format_custom(format_description!(
version = 2,
"[hour]:[minute]:[second].[subsecond digits:4]"
));
CombinedLogger::init(vec![TermLogger::new(
log_lvl,
log_cfg.build(),
Expand Down

0 comments on commit 0345e2d

Please sign in to comment.