Skip to content

Commit

Permalink
fix: make local times work again
Browse files Browse the repository at this point in the history
Due to https://rustsec.org/advisories/RUSTSEC-2020-0159, it wasn't possible
to get the local time in multi-threaded contexts. This was fixed with the
latest release v0.24 of `flexi_logger`. It is using a fixed version of
`chrono`, which also means that we don't have a dependency on `time` anymore.

Fixes #17.
Closes #18.
  • Loading branch information
vmx committed Oct 10, 2022
1 parent 8d600b1 commit 7f05a44
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Expand Up @@ -9,7 +9,6 @@ repository = "https://github.com/filecoin-project/rust-fil-logger"
readme = "README.md"

[dependencies]
flexi_logger = "0.22.3"
flexi_logger = "0.24.0"
log = "0.4.8"
atty = "0.2.13"
time = "0.3.9"
12 changes: 4 additions & 8 deletions src/lib.rs
Expand Up @@ -76,20 +76,16 @@ pub fn go_log_json_format(
writer,
r#"{{"level":"{}","ts":"{}","logger":"{}","caller":"{}:{}","msg":{:?}}}"#,
level,
now.format(GO_TIME_FORMAT),
now.now().format(GO_TIME_FORMAT),
record.module_path().unwrap_or("<unnamed>"),
record.file().unwrap_or("<unnamed>"),
record.line().unwrap_or(0),
&record.args().to_string()
)
}

const GO_TIME_FORMAT: &[time::format_description::FormatItem<'static>] = time::macros::format_description!(
"[year]-[month]-[day]T[hour]:[minute]:[second].[subsecond digits:3][offset_hour sign:mandatory][offset_minute]"
);
const DEFAULT_TIME_FORMAT: &[time::format_description::FormatItem<'static>] = time::macros::format_description!(
"[year]-[month]-[day]T[hour]:[minute]:[second].[subsecond digits:3]"
);
const GO_TIME_FORMAT: &str = "%Y-%m-%dT%H:%M:%S%.3f%z";
const DEFAULT_TIME_FORMAT: &str = "%Y-%m-%dT%H:%M:%S%.3f";

/// Logs with color, contains the same information as the [pretty_env_logger].
///
Expand All @@ -109,7 +105,7 @@ pub fn color_logger_format(
write!(
writer,
"{} {} {} > {}",
now.format(DEFAULT_TIME_FORMAT),
now.now().format(DEFAULT_TIME_FORMAT),
style(level).paint(level.to_string()),
record.module_path().unwrap_or("<unnamed>"),
record.args(),
Expand Down

0 comments on commit 7f05a44

Please sign in to comment.