#perl_noob has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,
I am trying to re initialize log4perl from a user given path which overrides the default configuration. Is this the right way to go about it since using only init() also works? Since both the approaches work, in which cases will reset() help? It is mentioned that reset() rests all the loggers to their initial state.

sub method { ... Log::Log4perl->reset(); Log::Log4perl->init($user_path); }
Looking forward to your views. Thank You.

Replies are listed 'Best First'.
Re: Views on reinitializing Log4perl
by thanos1983 (Parson) on Apr 26, 2017 at 14:50 UTC

    Hello #perl_noob,

    I do not think so, that reset() method is meant to be used the way you are using it.

    From the package documentation of package Log::Log4perl;

    ################################################## sub reset { # Mainly for debugging/testing ################################################## # Delegate this to the logger ... return Log::Log4perl::Logger->reset(); }

    Do you have a source of where you found someone applying this approach? Maybe I am wrong.

    But why not to try something like that (log4Perl dynamic filename)? Would this approach resolve your problem?

    Seeking for Perl wisdom...on the process of learning...not there...yet!

      My bad. I went through the source code of Log4perl and found that the Log4perl->init() delegates the initialization to Log4perl::Config->init() which uses reset() by default before going ahead with any initialization. So, no need to call reset() explicitly before init().
      Thank you for the input.