Swap time for chrono and log subsecond precision for times
authorMatt Corallo <git@bluematt.me>
Sun, 17 Oct 2021 00:50:34 +0000 (00:50 +0000)
committerMatt Corallo <git@bluematt.me>
Mon, 18 Oct 2021 21:43:07 +0000 (21:43 +0000)
The `time` crate appears to be basically undocumented (or, at
least, I couldn't find any documentation). `chrono` isn't super
well-documented, but at least its passable.

Cargo.toml
src/disk.rs

index fb9dd5ed0df2cea841eb497bd0b19ca791be38c3..cc9f50143a57d0d3e5c89cef281bcde97ff637b9 100644 (file)
@@ -22,7 +22,7 @@ bech32 = "0.8"
 hex = "0.3"
 
 futures = "0.3"
-time = "0.2"
+chrono = "0.4"
 rand = "0.4"
 serde_json = { version = "1.0" }
 tokio = { version = "1.5", features = [ "io-util", "macros", "rt", "rt-multi-thread", "sync", "net", "time" ] }
index 2c1834a6f0b7ac92caec7c712a659dd25786c718..b641ebb053167b01c6f397c1ef40d0decd98ad61 100644 (file)
@@ -1,6 +1,7 @@
 use crate::cli;
 use bitcoin::secp256k1::key::PublicKey;
 use bitcoin::BlockHash;
+use chrono::Utc;
 use lightning::routing::network_graph::NetworkGraph;
 use lightning::util::logger::{Logger, Record};
 use lightning::util::ser::{Readable, Writeable, Writer};
@@ -10,7 +11,6 @@ use std::fs::File;
 use std::io::{BufRead, BufReader, BufWriter};
 use std::net::SocketAddr;
 use std::path::Path;
-use time::OffsetDateTime;
 
 pub(crate) struct FilesystemLogger {
        data_dir: String,
@@ -27,7 +27,10 @@ impl Logger for FilesystemLogger {
                let raw_log = record.args.to_string();
                let log = format!(
                        "{} {:<5} [{}:{}] {}\n",
-                       OffsetDateTime::now_utc().format("%F %T"),
+                       // Note that a "real" lightning node almost certainly does *not* want subsecond
+                       // precision for message-receipt information as it makes log entries a target for
+                       // deanonymization attacks. For testing, however, its quite useful.
+                       Utc::now().format("%Y-%m-%d %H:%M:%S%.3f"),
                        record.level.to_string(),
                        record.module_path,
                        record.line,