in reply to Re: Graceful handling of Log::Log4perl errors
in thread Graceful handling of Log::Log4perl errors
my %paths = (); my $init_fail = 0; INIT: while (1) { eval {Log::Log4perl->init_once($LOGGER_CONF_FILE)}; if ($@) { # Config file error of some kind # Send some alert message here # if we get a missing directory error, try some (sane) recover +y if ($@ =~ m{Can't\sopen\s/my/base/path/(.+)\s\(No such file or + directory\)}) { my $path = $1; if ( $paths{$path}++ ) { # only try once to create a give +n path. This prevents infinite loops here $init_fail = 1; last INIT; } my $dir = "/my/base/path"; # if the base path isn't th +ere, creating it is above this module's pay grade my @dir_list = split '/', $path; my $file = pop @dir_list; foreach my $sub_dir (@dir_list) { $dir .= "/$sub_dir"; if (! -d$dir) { eval {mkdir ($dir)}; # not too concerned with catc +hing errors here, the next round will bail on duplicate path attempt } } } # for other config file errors, throw our hands up in disgust +and move on else { $init_fail = 1; last INIT; } } else { $init_fail = 0; last INIT; } } # if we couldn't get the config file to initlize, load a blank one and + move on without logging if ($init_fail) { warn "Couldn't initilize logger, defaulting to blank config file"; my $default_config_file = "/my/base/path/etc/default.logger.conf"; open (my $fh, ">", $default_config_file); close ($fh); Log::Log4perl::init_once($default_config_file); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Graceful handling of Log::Log4perl errors
by kyle (Abbot) on May 29, 2008 at 02:29 UTC | |
by chaos_cat (Scribe) on May 29, 2008 at 15:16 UTC |