Skip to content

Commit

Permalink
feat: add timestamp placeholder to log file name, fix datetime format…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
simongoricar committed Aug 7, 2023
1 parent 30e3876 commit 37d9172
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/configuration/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::BTreeMap;
use std::fs;
use std::path::{Path, PathBuf};

use chrono::Local;
use miette::{miette, Context, Result};
use serde::Deserialize;

Expand Down Expand Up @@ -166,13 +167,17 @@ impl AfterLoadWithPathsInitable for LoggingConfig {
.to_string_lossy()
.to_string();

let time_now = Local::now();
let formatted_time_now = time_now.format("%Y-%m-%d_%H-%M-%S");

self.default_log_output_path =
self.default_log_output_path.as_ref().map(|output_path| {
let path_as_string = output_path
.to_string_lossy()
.to_string()
.replace("{LIBRARY_BASE}", &paths.base_library_path)
.replace("{SELF}", &executable_directory);
.replace("{SELF}", &executable_directory)
.replace("{DATETIME}", &formatted_time_now.to_string());

PathBuf::from(path_as_string)
});
Expand Down
4 changes: 2 additions & 2 deletions src/console/frontends/terminal_ui/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl<'thread_scope, 'config> LogBackend
LogOutputMode::ToFile { buf_writer, .. } => {
let time_now = Local::now();
let formatted_time_now =
time_now.format("%d-%m-%Y@%H:%M:%S%.3f ");
time_now.format("%Y-%m-%d %H:%M:%S%.3f ");

let mut locked_buf_writer = buf_writer.lock();

Expand Down Expand Up @@ -346,7 +346,7 @@ impl<'scope, 'scope_env: 'scope, 'config: 'scope>

// Write an "invocation header", marking the start of euphony.
let time_now = Local::now();
let formatted_time_now = time_now.format("%d-%m-%Y@%H:%M:%S%.3f");
let formatted_time_now = time_now.format("%Y-%m-%d %H:%M:%S%.3f");

buf_writer
.write_all(
Expand Down

0 comments on commit 37d9172

Please sign in to comment.