estk / log4rs

A highly configurable logging framework for Rust
Apache License 2.0
998 stars 147 forks source link

Prevent log4rs from creating $ENV{HOME} folders everywhere #314

Closed qkzk closed 9 months ago

qkzk commented 1 year ago

I may be wrong since I haven't read the whole source code...

When I setup the logs an $ENV{HOME} is created in CWD. I guess it comes from this, since I'm using a fixed_window roller with a pattern. :

documentation

    /// Consumes the `FileAppenderBuilder`, producing a `FileAppender`.
    /// The path argument can contain environment variables of the form $ENV{name_here},
    /// where 'name_here' will be the name of the environment variable that
    /// will be resolved. Note that if the variable fails to resolve,
    /// $ENV{name_here} will NOT be replaced in the path.
    pub fn build<P: AsRef<Path>>(self, path: P) -> io::Result<FileAppender> {
        ...

I want to log in the $HOME/.config but I sometime end with a folder named $ENV{HOME}... Here's an extract from the log config file :

appenders:
  normal_logger:
    kind: rolling_file
    path: "$ENV{HOME}/.config/bla/log/bla.log"
    encoder:
      pattern: "{d(%Y-%m-%d %H:%M:%S)} - {h({l})}: {m} - {f}:{L}{n}"
    policy:
      trigger:
        kind: size
        limit: 50kb
      roller:
        kind: fixed_window
        base: 1
        count: 10
        pattern: "$ENV{HOME}/.config/bla/log/bla{}.log"

What am I doing wrong ? Obviously $ENV{HOME} is always set.

jonatansalemes commented 1 year ago

source code doest not reflect crate at this time, needs build new version incrate with env var expansion

qkzk commented 1 year ago

Ahhh Okay :) I'll try the GitHub version then. I'll let you know how it works.

bconn98 commented 9 months ago

@qkzk Any update?

qkzk commented 9 months ago

Hello,

Yes, it works. There's no $Env{HOME} created anymore.

Sorry I completely forgot about this issue.