in reply to Graceful handling of Log::Log4perl errors
I think your use of eval to implement a fail safe is a good way to go. One thing you could add to that is trying to figure out what directory it wants to use and then create it.
eval { bork_bork_bork }; if ( $@ =~ m{ \A Can't \s open \s ( .+ ) / ( [^/]+ ) \s }xms ) { my ( $missing_dir, $log_filename ) = ( $1, $2 ); if ( ! -d $missing_dir ) { # try to make the directory } }
If you manage to get the broken config working, the first thing you'll want to do is log that.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Graceful handling of Log::Log4perl errors
by chaos_cat (Scribe) on May 28, 2008 at 21:57 UTC | |
| [reply] [d/l] |
by kyle (Abbot) on May 29, 2008 at 02:29 UTC | |
That looks pretty good! I'm gratified that you took my suggestion and ran with it. Thanks for sharing it with us! Looking at what you have, I think it could be made a bit more compact.
Note the differences, though (good and bad).
Thanks again for posting your work. | [reply] [d/l] [select] |
by chaos_cat (Scribe) on May 29, 2008 at 15:16 UTC | |
I incorporated a few of your changes. In particular, I like the $init_done mechanic; it's much cleaner than what I was doing.
One thing I learned while doing this: Log4perl sets its initialized flag at the beginning of its initialization, not at the end (on line 113 of Log::Log4perl::Config, in _init, on my install at least), so using init_once here is problematic, as it will not reload after the directory is created. I switched over to using init and relying on the $init_done to guard against unintentional reinitialization. Once I did that, it was necessary to put back in the two level error message check (the else last bit), otherwise it infinite loops because it is dieing on an unrecognized message. Thanks for all your help! | [reply] [d/l] |