log4rs
log4rs copied to clipboard
Fixed window roller expand env var
This PR implements expanding env vars in file patterns in FixedWindowRoller
as requested here https://github.com/estk/log4rs/issues/280 .
@Caleb-Hill Horay!
Thanks for opening a PR.
I really like the change from taking a PathBuf
to String
, and after looking it over I think we can take this to 11. I suggest the following type for expand_env_vars
.
pub fn expand_env_vars<'str, Str>(s: Str) -> Cow<'str, str>
where
Str: Into<Cow<'str, str>>,
{
let orig_path: Cow<str> = s.into();
let mut out_path = orig_path.clone();
The nice thing about this is that the ref gets passed all the way through so that in many cases there may be zero allocations. I know its a bit of a funny optimization, but...
There will be a few other resulting changes such as:
let src_str = expand_env_vars(pattern.replace("{}", &i.to_string()));
let src = Path::new(src_str.as_ref());
let dst_str = expand_env_vars(pattern.replace("{}", &(i + 1).to_string()));
let dst = Path::new(dst_str.as_ref());
I really appreciate your time, and thanks again!
Additionally, as a note, i've been thinking about switching over to camino
Updated it to use Cow, sorry I just got around to it. Somehow the github email ended up in my spam folder.
Additionally, as a note, i've been thinking about switching over to camino
This seems like a good idea but probably a separate PR at least to my eyes.
@estk Could you run the workflow and or re review my changes please?
Fixed redundant clone lint issue on previous version.