Error when changing working directory
if the current directory is changed, log4rs pumps a error message to stderr:
log4rs: No such file or directory (os error 2)
This is my Cargo.toml config:
[dependencies]
log = "0.4"
log4rs = { version ="1.2", features = ["gzip"] }
This is the test program:
use log::*;
use log4rs;
use std::{thread, time::Duration};
fn main() -> Result<(), std::io::Error> {
log4rs::init_file("log4rs.yaml", Default::default()).expect("Open log4rs config");
info!("Starting up");
// if this line is commented, the error goes away
std::env::set_current_dir(&std::path::Path::new("/tmp"))?;
for i in 1..11 {
info!("{i}");
thread::sleep(Duration::from_millis(1500));
}
info!("Finished");
Ok(())
}
This is log4rs.yaml:
refresh_rate: 2 seconds
appenders:
stdout:
kind: console
encoder:
pattern: "[{d(%Y-%m-%d %H:%M:%S)} {l}] {m}{n}"
requests:
kind: file
path: "my.log"
encoder:
pattern: "[{d(%Y-%m-%d %H:%M:%S)} {l}] {m}{n}"
root:
level: info
# level: debug
appenders:
- stdout
- requests
loggers:
app::requests:
level: debug
appenders:
- requests
additive: false
I apologize if this is the desired behavior and this is not an error.
maybe you forget to copy log4rs.yaml to your program's directory?
No, the error happend only if this call is in effect (try comment it out)
std::env::set_current_dir(&std::path::Path::new("/tmp"));
El mié, 15 mar. 2023 14:00, Dirreck @.***> escribió:
maybe you forget to copy log4rs.yaml to your program's directory?
— Reply to this email directly, view it on GitHub https://github.com/estk/log4rs/issues/297#issuecomment-1470412395, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALBP4GQHA5A4GGP47CPBLLW4HYUHANCNFSM6AAAAAATT4SUEI . You are receiving this because you authored the thread.Message ID: @.***>