Thanks for the suggestion. I built the following code based on your idea, which seems to do the trick. It makes repeated attempts to load the config file and correct for missing path errors. If it encounters an error it doesn't recognize, or if it can't get a path created, it gives up and loads a blank config file (which it creates then and there to be sure it's blank). So far, it's passed all my tests but if anyone sees something broken here please drop me a note.
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);
}