On Thu, 27 Dec 2012, Hugh Esco wrote:

> I'm curious how the Log::Log4perl class knows what config file to read
> when I invoke the ->appender_by_name() method.

The appender_by_name method assumes L4p configuration has already
happened. If you want to read from a config file, you need to call
init() beforehand.

> Also, once I have an $appender object, will ->filename() provide only
> the filename, or also its path?

You'll get the exact value as specified in the configuration. It could
be an absolute path or a relative path or a filename (relative to
cwd()).

-- 
-- Mike

Mike Schilli
m...@perlmeister.com

>  I'm pretty sure my issue relates to a missing path, not L4P's
>  inability to create the file in that path when needed.
>
> Thanks again,
> -- Hugh Esco
>
> Date: Thu, 27 Dec 2012 11:27:36 -0800 (PST)
> From: Mike Schilli <m...@perlmeister.com>
> Reply-To: Mike Schilli <m...@perlmeister.com>
> To: Hugh Esco <he...@campaignfoundations.com>
> cc: log4perl-devel@lists.sourceforge.net
> Subject: Re: [log4perl-devel] Introspecting the $logger object for log file
> path  and name?
>
> 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...@perlmeister.com
>
>
>
>>
>> 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?
>>
>>
>
>

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122712
_______________________________________________
log4perl-devel mailing list
log4perl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/log4perl-devel

Reply via email to