my %paths = (); my $init_done = 0; my $base_path = "/my/base/path/"; INIT: while ( !$init_done ) { $init_done = eval { Log::Log4perl->init($LOGGER_CONF_FILE); 1; }; if ($@) { warn "Logger error was: $@"; # if we get a missing directory error, try some (sane) recovery if ( $@ =~ m{Can't\sopen\s$base_path(.+)/[^/]+\s\(No such file or directory\)} ) { my $path = $1; $path = $base_path . $path; warn "log directory $path does not exist, attempting to create it"; if ( $paths{$path}++ ) { warn "alredy tried to create this path"; last INIT; } eval { mkpath($path) }; warn "unable to create path $path" if ( !-d $path ); } # for other config file errors, throw our hands up in disgust and move on else { last INIT; } } } # if we couldn't get the config file to initlize, load a blank one and move on without logging if ( ! $init_done ) { warn "Couldn't initilize logger, defaulting to blank config file"; Log::Log4perl::init(\''); # this will throw a warning, but that's not really a bad thing }