Skip to content

Commit

Permalink
proper migration to time 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatonik committed Feb 7, 2022
1 parent a567abc commit 8f11e3f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion relays/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ log = "0.4.11"
num-traits = "0.2"
serde_json = "1.0"
sysinfo = "0.15"
time = "0.3"
time = { version = "0.3", features = ["formatting", "local-offset", "std"] }
thiserror = "1.0.26"

# Bridge dependencies
Expand Down
12 changes: 9 additions & 3 deletions relays/utils/src/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@ pub fn initialize_relay() {

/// Initialize Relay logger instance.
pub fn initialize_logger(with_timestamp: bool) {
let format = time::format_description::parse(
"[year]-[month]-[day] \
[hour repr:24]:[minute]:[second] [offset_hour sign:mandatory]",
)
.expect("static format string is valid");

let mut builder = env_logger::Builder::new();
builder.filter_level(log::LevelFilter::Warn);
builder.filter_module("bridge", log::LevelFilter::Info);
builder.parse_default_env();
if with_timestamp {
builder.format(move |buf, record| {
let timestamp = time::OffsetDateTime::try_now_local()
.unwrap_or_else(|_| time::OffsetDateTime::now_utc())
.format("%Y-%m-%d %H:%M:%S %z");
let timestamp = time::OffsetDateTime::now_local()
.unwrap_or_else(|_| time::OffsetDateTime::now_utc());
let timestamp = timestamp.format(&format).unwrap_or_else(|_| timestamp.to_string());

let log_level = color_level(record.level());
let log_target = color_target(record.target());
Expand Down

0 comments on commit 8f11e3f

Please sign in to comment.