|
From: Mike S. <m...@pe...> - 2012-12-27 19:27:56
|
On Thu, 27 Dec 2012, Hugh Esco wrote:
> Using Log::Log4perl, I need to test for the existence of a log path and
> create it if necessary, I had hopes that this might give me what I was
> looking for:
>
> my $path =
> Log::Log4perl->appender_by_name(
> 'log4perl.appender.A1.filename');
Hi Hugh,
looks what you want to find out is if a file appender's log file is
present before you start your program. Note that this is not related to
the logger object, but to the appender object instead.
First off, Log4perl will create missing log files. You can do this
either at log time or at init time. The former is the default behavior,
the second is triggered by the 'create_at_logtime' option. See 'perldoc
Log::Log4perl::Appender::File' for this and other create/recreate
options.
Now, there are cases where you want to make sure the log file exists
before you init Log4perl, e.g. if the program's permissions don't allow
for creating the log file, but then you need to create it outside the
program anyway. Typically package installers (like rpm, dpkg etc.) take
care of this.
Anyway, if you want access to the file appender's filename, you need to change
the line
> Log::Log4perl->appender_by_name(
> 'log4perl.appender.A1.filename');
to something like
my $appender = Log::Log4perl->appender_by_name( 'A1' );
print $appender->filename();
Hope that helps, let me know if you need anything else!
-- -- Mike
Mike Schilli
m...@pe...
>
> But I am getting (on the next line):
>
> Use of uninitialized value $path in substitution.
>
> Is there some way to query the class or perhaps the $logger object for
> what path and filename it expects from the configuration so I can
> created it before it is needed and its absence blows things up?
>
> I would try this with the $logger object itself, but attempting to
> instantiate one when the log file's path is missing blows things up.
>
> How do I automate this process so that an arbitrary path and file are
> created when my application is deployed into a fresh bare-metal
> environment?
>
>
|