Skip to content

Commit

Permalink
better log file names
Browse files Browse the repository at this point in the history
  • Loading branch information
astraw committed Jul 13, 2024
1 parent 2b939b1 commit 2a57112
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
11 changes: 4 additions & 7 deletions braid/braid-run/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,10 @@ async fn main() -> Result<()> {
)
})?;

let log_file_name = format!(
"~/.braid-{}.log",
std::time::SystemTime::UNIX_EPOCH
.elapsed()
.unwrap()
.as_micros(),
);
let log_file_name = chrono::Local::now()
.format("~/.braid-%Y%m%d_%H%M%S.%f.log")
.to_string();

let log_file_name = std::path::PathBuf::from(shellexpand::full(&log_file_name)?.to_string());
// TODO: delete log files older than, e.g. one week.

Expand Down
24 changes: 8 additions & 16 deletions strand-cam/src/strand-cam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,14 +1000,10 @@ where
// include the camera name. We need to start logging as soon as possible
// (before we necessarily know the camera name) because we may need to debug
// connectivity problems to Braid or problems starting the camera.
let initial_log_file_name = format!(
"~/.strand-cam-{}-{}.log",
std::time::SystemTime::UNIX_EPOCH
.elapsed()
.unwrap()
.as_micros(),
std::process::id()
);
let initial_log_file_name = chrono::Local::now()
.format("~/.strand-cam-%Y%m%d_%H%M%S.%f")
.to_string()
+ &format!("-{}.log", std::process::id());
let initial_log_file_name =
std::path::PathBuf::from(shellexpand::full(&initial_log_file_name)?.to_string());
// TODO: delete log files older than, e.g. one week.
Expand Down Expand Up @@ -1257,14 +1253,10 @@ where

// Rename the log file (which is open and being written to) so that the name
// includes the camera name.
let new_log_file_name = format!(
"~/.strand-cam-{}-{}.log",
std::time::SystemTime::UNIX_EPOCH
.elapsed()
.unwrap()
.as_micros(),
use_camera_name
);
let new_log_file_name = chrono::Local::now()
.format("~/.strand-cam-%Y%m%d_%H%M%S.%f")
.to_string()
+ &format!("-{}.log", use_camera_name);
let new_log_file_name =
std::path::PathBuf::from(shellexpand::full(&new_log_file_name)?.to_string());
tracing::debug!(
Expand Down

0 comments on commit 2a57112

Please sign in to comment.