Skip to content

Commit

Permalink
fix: windows path format in log4rs files (#5234)
Browse files Browse the repository at this point in the history
Description
---
This commit does a naive character replacement on the string path just
before we do the path injection.

Motivation and Context
---
log4rs expects the paths to be in a unix format regardless of the system
it's running on. When we started doing the dynamic injecting of the base
path windows systems injected using a windows format, which mixed with
the unix format. Resulting in strings that looked liked this:
`C:\\brianp\.tari\config/log/base-node/network.log`

when log4rs wants the final format to be like this:
`C://brianp/.tari/config/log/base-node/network.log`

How Has This Been Tested?
---
Manually on Hansie's windows machine

Co-authored-by: hansieodendaal
39146854+hansieodendaal@users.noreply.github.com
  • Loading branch information
brianp authored Mar 15, 2023
1 parent 76aeed7 commit acfecfb
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions common/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ pub fn initialize_logging(config_file: &Path, base_path: &Path, default: &str) -
file.read_to_string(&mut contents)
.map_err(|e| ConfigError::new("Could not read file: {}", Some(e.to_string())))?;

let contents = contents.replace(
"{{log_dir}}",
base_path
.to_str()
.expect("Could not replace {{log_dir}} variable from the log4rs config"),
);
let replace_str = base_path
.to_str()
.expect("Could not replace {{log_dir}} variable from the log4rs config")
// log4rs requires the path to be in a unix format regardless of the system it's running on
.replace("\\", "/");

let contents = contents.replace("{{log_dir}}", &replace_str);

let config: RawConfig =
serde_yaml::from_str(&contents).expect("Could not parse the contents of the log file as yaml");
Expand Down

0 comments on commit acfecfb

Please sign in to comment.