From: Hugh E. <he...@ca...> - 2012-12-27 17:30:56
|
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'); 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? -- Hugh Esco skype: hresco3_ ; 678-921-8186 http://www.CampaignFoundations.com/ Providing Application Hosting, Telephony, Custom Development and Consulting Services to Green Candidates, Green Parties and the non profits working for a just and sustainable future. if( $insurance->rationing() ) { $people->die(); } if( isa_ok($self,'Troy::Davis') =~ m/^ok/) { $people->are_whole(); } |
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? > > |
From: <he...@gr...> - 2012-12-27 19:44:25
|
Thank you. I will take a closer look at this once I am home. I'm curious how the Log::Log4perl class knows what config file to read when I invoke the ->appender_by_name() method. Also, once I have an $appender object, will ->filename() provide only the filename, or also its path? 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...@pe...> Reply-To: Mike Schilli <m...@pe...> To: Hugh Esco <he...@ca...> cc: log...@li... 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...@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? > > |
From: Mike S. <m...@pe...> - 2012-12-27 19:50:14
|
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...@pe... > 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...@pe...> > Reply-To: Mike Schilli <m...@pe...> > To: Hugh Esco <he...@ca...> > cc: log...@li... > 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...@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? >> >> > > |