From: Ronald F. <yn...@mm...> - 2009-03-06 09:00:33
|
Resent of my posting from 24 Feb which seems to have been lost. ----- Original message ----- From: "Ronald Fischer" <yn...@mm...> To: "Mike Schilli" <m...@pe...> Cc: "Mike Schilli" <m...@pe...>, "log4perl MailingList" <log...@li...> Date: Tue, 24 Feb 2009 09:52:06 +0100 Subject: Re: [log4perl-devel] Appender::File and Layout question On Mon, 23 Feb 2009 08:34 -0800, "Mike Schilli" <m...@pe...> wrote: > > The other problem is that I would strongly prefer a solution without > > l4p configuration file. The reason is that one requirement for our > > application was "one config file only", so we have an application > > specific configuration file, so I'm using easy_init to initialize the > > logging. > > Everything you can do in a configuration file can be done in code with > the Log4perl API, problem is just that it might get confusing if you're > trying to figure out what's going on by looking at the configuration > file, while application code is pulling the rug under it :). Right, but this is a decision I don't want to (actually, I must not) decide by myself, but this must be done by the project leader, which means that I have to at least demonstrate both ways. Thanks to your explanations, I understand how to do it in a config file, but I don't see how to do it in my code. Probably it is not possible at all with easy_init (which I would like to continue to use) - at least I can't find anything suitable in the perldoc of Log::Log4perl. There is something in the section "Advanced Perl Configuration", but I don't see how to use it in my case. This is how far I got: # This is my current initialization Log::Log4perl->easy_init( # ... Details left out ); # Now define the request-specific logger use Log::Log4perl::Layout; use Log::Log4perl::Level; my $req_logger= Log::Log4perl->get_logger(???); my $req_appender = Log::Log4perl::Appender->new( "Log::Log4perl::Appender::File", name => "???", mode => 'clobber', utf8 => 1, create_at_logtime => 1 filename => \&get_current_logfile); # ??? $req_appender->layout(Log::Log4perl::Layout::PatternLayout->new("...")); $req_logger->add_appender($req_appender); $req_logger->level($INFO); And when it comes to logging something to the request logger, I would write i.e. $req_logger->loginfo("my message goes here"); I don't know whether the general idea is right or whether there is a shorter way to write it, but still there are a few open points, which I have marked in my code above with ???. First, what category string should I pass to get_logger? We don't work with categories, and we have none defined with easy_init, so it would make sense to me to pass the "default category". Could this be done by passing, say, the null string? Second, what is the "name" parameter used for when creating the Appender. I found the usage of name => in the perldoc, but what's its purpose? Finally, is my usage of passing a code reference to filename correct? Kind regards, Ronald > > -- Mike > > Mike Schilli > m...@pe... -- Ronald Fischer <ro...@em...> + If a packet hits a pocket on a socket on a port, + and the bus is interrupted and the interrupt's not caught, + then the socket packet pocket has an error to report. + (cited after Peter van der Linden) -- Ronald Fischer <ro...@em...> + If a packet hits a pocket on a socket on a port, + and the bus is interrupted and the interrupt's not caught, + then the socket packet pocket has an error to report. + (cited after Peter van der Linden) |
From: Mike S. <m...@pe...> - 2009-03-06 16:53:10
|
On Fri, 6 Mar 2009, Ronald Fischer wrote: > I understand how to do it in a config file, but I don't see how to do > it in my code. Probably it is not possible at all with easy_init > (which I would like to continue to use) easy_init() and init() are using the same underlying internal Log4perl API functions, so it doesn't matter which one you're using. > # This is my current initialization > Log::Log4perl->easy_init( > # ... Details left out > ); > # Now define the request-specific logger > > use Log::Log4perl::Layout; > use Log::Log4perl::Level; > my $req_logger= Log::Log4perl->get_logger(???); Since you don't want categories, use the root logger here: my $req_logger= Log::Log4perl->get_logger(""); > my $req_appender = Log::Log4perl::Appender->new( > "Log::Log4perl::Appender::File", > name => "???", You can omit the name. > mode => 'clobber', > utf8 => 1, > create_at_logtime => 1 > filename => \&get_current_logfile); # ??? You don't want to pass a reference here, you want to call the function right here: filename => get_current_logfile() ); and define it like sub get_current_logfile { return "logfile.dat"; } or whatever fance logic you want it to use, but it needs to return the name of the file. So, a working version of what you want would look something like this: use strict; use Log::Log4perl qw(:easy); # This is my current initialization Log::Log4perl->easy_init($DEBUG); use Log::Log4perl::Layout; use Log::Log4perl::Level; my $req_logger= Log::Log4perl->get_logger(""); my $req_appender = Log::Log4perl::Appender->new( "Log::Log4perl::Appender::File", mode => 'clobber', utf8 => 1, create_at_logtime => 1, filename => get_current_logfile()); $req_appender->layout(Log::Log4perl::Layout::SimpleLayout->new()); $req_logger->add_appender($req_appender); DEBUG "waah"; ########################################### sub get_current_logfile { ########################################### return "logfile.dat"; } One more thing: A logger (the root logger in your case) can only have one level. So if you initialize with easy_init($DEBUG), that's the level it's gonna have. If you want different levels for the file appender you're setting up manually, use appender thresholds or a filter. Hope that helps! -- Mike Mike Schilli m...@pe... |
From: Ronald F. <yn...@mm...> - 2009-03-10 10:59:40
|
On Mon, 09 Mar 2009 12:09 -0700, "Mike Schilli" <m...@pe...> wrote: > A, gotcha, I forgot that you have a long-running process and want to > switch log files for every request. To do that, you can write your own > appender (it's very easy, check > http://search.cpan.org/dist/Log-Log4perl/lib/Log/Log4perl/FAQ.pm#How_can_I_write_my_own_appender?) > or, alternatively, when you get a request, run > > Log::Log4perl->appender_by_name("LogApp")->file_switch("log$$.log"); > > given that "LogApp" is the name of the appender in your Log4perl > configuration (if you're using :easy, its name is "app001"). I like the use of file_switch, because this seems to map perfectly well to the design I have right now. If I use easy_init like this: Log::Log4perl->easy_init( {level => $log_level, file => 'STDOUT', layout => '%.1p %d{HH:mm} %M(%L) %m%n' }, {level => $log_level, file => ">main.log", layout => '%.1p %d{dd.MM. HH:mm:ss (EEE)} %M(%L) %m%n' } {level => $log_level, file => '>dummy.log'), layout => '%.1p %d{HH:mm} %M(%L) %m%n' }, ); I guess the name of the "dummy.log" appender then is app003, so I would have to switch it by Log::Log4perl->appender_by_name('app003')->file_switch(get_request_logfile()); or alternatively that I explicitly provide logger names, i.e. Log::Log4perl->easy_init( {level => $log_level, file => 'STDOUT', layout => '%.1p %d{HH:mm} %M(%L) %m%n' }, {level => $log_level, file => ">main.log", layout => '%.1p %d{dd.MM. HH:mm:ss (EEE)} %M(%L) %m%n' } {level => $log_level, file => '>dummy.log'), layout => '%.1p %d{HH:mm} %M(%L) %m%n', name => 'requestlogger' }, ); ... Log::Log4perl->appender_by_name('requestlogger')->file_switch(get_request_logfile()); Is this correct? Regards, Ronald -- Ronald Fischer <ro...@em...> + If a packet hits a pocket on a socket on a port, + and the bus is interrupted and the interrupt's not caught, + then the socket packet pocket has an error to report. + (cited after Peter van der Linden) |
From: DAY R. <Rog...@at...> - 2009-03-10 17:34:49
|
Hi Every time I run a script, I'd like my log-file to roll over. I invoke Log::Dispatch::FileRotate thusly my $file_appender = Log::Log4perl::Appender>new("Log::Dispatch::FileRotate", name => "Logfile", mode => "append", filename => $logfile, TZ => 'GMT', DatePattern => 'HH-dd-yyyy',); But it doesn't seem to make a difference ... unless I've fallen into an ActiveState hole again ... Roger **************************************************************** The operating companies affiliated with Atradius N.V. (Atradius Group) conduct insurance, debt collection and information services business through their registered (branch) offices in many countries. For information about the main registration details of Atradius Group offices in your country please visit http://global.atradius.com/general-content/legal/legallist.html IMPORTANT NOTICE. This e-mail, including any and all attachments, is intended for the addressee or its representative only. It is confidential and may be under legal privilege. Any form of unauthorised use, publication, reproduction, copying or disclosure of the content of this e-mail is not permitted. If you are not the intended recipient of this e-mail and its contents, please notify the sender immediately by reply e-mail and delete this e-mail and all its attachments subsequently. Although this e-mail and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and/or opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by Atradius Group companies, either jointly or severally, for any loss or damage arising in any way from its use. E-mail received by Atradius Group can be stored for business purposes. **************************************** |
From: Mike S. <m...@pe...> - 2009-03-11 07:37:04
|
On Tue, 10 Mar 2009, DAY Roger wrote: > Every time I run a script, I'd like my log-file to roll over. I invoke > Log::Dispatch::FileRotate thusly >... > DatePattern => 'HH-dd-yyyy',); Hmm, this is neither a valid date pattern (yyyy-MM-dd-HH would be correct), according to the Log::Dispatch::FileRotate man page, nor does it claim to roll it on every invocation. You probably need something like a custom file appender for this. -- Mike Mike Schilli m...@pe... |
From: DAY R. <Rog...@at...> - 2009-03-11 09:33:03
|
This from the web-page: "I initially aasumed a long runinng process but it seems people are using this module as part of short running CGI programs. So, now we look at the last modified time stamp of the log file and compare it to a previous occurance of a DatePattern, on startup only. If the file stat shows the mtime to be earlier than the previous recurrance then I rotate the log file." Which I take to mean it does do invocation-like rollovers. If this doesn't work, I'll resort to a custom file appender. I see what you mean about the valid date patterns. Implement in haste, repent at leisure. Also, apologies for the stupid .sig. I have no control over it. Roger -----Original Message----- From: Mike Schilli [mailto:m...@pe...] Sent: 11 March 2009 07:37 To: DAY Roger Cc: log4perl MailingList Subject: Re: [log4perl-devel] rotation on new run of script On Tue, 10 Mar 2009, DAY Roger wrote: > Every time I run a script, I'd like my log-file to roll over. I invoke > Log::Dispatch::FileRotate thusly >... > DatePattern => 'HH-dd-yyyy',); Hmm, this is neither a valid date pattern (yyyy-MM-dd-HH would be correct), according to the Log::Dispatch::FileRotate man page, nor does it claim to roll it on every invocation. You probably need something like a custom file appender for this. -- Mike Mike Schilli m...@pe... **************************************************************** The operating companies affiliated with Atradius N.V. (Atradius Group) conduct insurance, debt collection and information services business through their registered (branch) offices in many countries. For information about the main registration details of Atradius Group offices in your country please visit http://global.atradius.com/general-content/legal/legallist.html IMPORTANT NOTICE. This e-mail, including any and all attachments, is intended for the addressee or its representative only. It is confidential and may be under legal privilege. Any form of unauthorised use, publication, reproduction, copying or disclosure of the content of this e-mail is not permitted. If you are not the intended recipient of this e-mail and its contents, please notify the sender immediately by reply e-mail and delete this e-mail and all its attachments subsequently. Although this e-mail and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and/or opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by Atradius Group companies, either jointly or severally, for any loss or damage arising in any way from its use. E-mail received by Atradius Group can be stored for business purposes. **************************************** |
From: Mike S. <m...@pe...> - 2009-03-11 15:41:04
|
On Wed, 11 Mar 2009, DAY Roger wrote: > Which I take to mean it does do invocation-like rollovers. If this > doesn't work, I'll resort to a custom file appender. Actually, you could use something like this: log4perl.appender.Logfile = Log::Log4perl::Appender::File log4perl.appender.Logfile.filename = sub { "log-" . time() . ".log" } to name your logfiles after the current timestamp? -- Mike Mike Schilli m...@pe... > > I see what you mean about the valid date patterns. Implement in haste, > repent at leisure. > > Also, apologies for the stupid .sig. I have no control over it. > > Roger > > -----Original Message----- > From: Mike Schilli [mailto:m...@pe...] > Sent: 11 March 2009 07:37 > To: DAY Roger > Cc: log4perl MailingList > Subject: Re: [log4perl-devel] rotation on new run of script > > On Tue, 10 Mar 2009, DAY Roger wrote: > >> Every time I run a script, I'd like my log-file to roll over. I invoke >> Log::Dispatch::FileRotate thusly >> ... >> DatePattern => 'HH-dd-yyyy',); > > Hmm, this is neither a valid date pattern (yyyy-MM-dd-HH would be > correct), according to the Log::Dispatch::FileRotate man page, nor does > it claim to roll it on every invocation. > > You probably need something like a custom file appender for this. > > -- Mike > > Mike Schilli > m...@pe... > > **************************************************************** > The operating companies affiliated with Atradius N.V. (Atradius Group) conduct insurance, debt collection and information services business through their registered (branch) offices in many countries. For information about the main registration details of Atradius Group offices in your country please visit http://global.atradius.com/general-content/legal/legallist.html > > IMPORTANT NOTICE. This e-mail, including any and all attachments, is intended for the addressee or its representative only. It is confidential and may be under legal privilege. Any form of unauthorised use, publication, reproduction, copying or disclosure of the content of this e-mail is not permitted. If you are not the intended recipient of this e-mail and its contents, please notify the sender immediately by reply e-mail and delete this e-mail and all its attachments subsequently. > > Although this e-mail and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and/or opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by Atradius Group companies, either jointly or severally, for any loss or damage arising in any way from its use. E-mail received by Atradius Group can be stored for business purposes. > **************************************** > > > |
From: DAY R. <Rog...@at...> - 2009-03-11 16:13:38
|
That would work, cheers. I was thinking it'll be fun to write a custom appender. I'll think on it. Roger -----Original Message----- From: Mike Schilli [mailto:m...@pe...] Sent: 11 March 2009 15:41 To: DAY Roger Cc: Mike Schilli; log4perl MailingList Subject: RE: [log4perl-devel] rotation on new run of script On Wed, 11 Mar 2009, DAY Roger wrote: > Which I take to mean it does do invocation-like rollovers. If this > doesn't work, I'll resort to a custom file appender. Actually, you could use something like this: log4perl.appender.Logfile = Log::Log4perl::Appender::File log4perl.appender.Logfile.filename = sub { "log-" . time() . ".log" } to name your logfiles after the current timestamp? -- Mike Mike Schilli m...@pe... > > I see what you mean about the valid date patterns. Implement in haste, > repent at leisure. > > Also, apologies for the stupid .sig. I have no control over it. > > Roger > > -----Original Message----- > From: Mike Schilli [mailto:m...@pe...] > Sent: 11 March 2009 07:37 > To: DAY Roger > Cc: log4perl MailingList > Subject: Re: [log4perl-devel] rotation on new run of script > > On Tue, 10 Mar 2009, DAY Roger wrote: > >> Every time I run a script, I'd like my log-file to roll over. I invoke >> Log::Dispatch::FileRotate thusly >> ... >> DatePattern => 'HH-dd-yyyy',); > > Hmm, this is neither a valid date pattern (yyyy-MM-dd-HH would be > correct), according to the Log::Dispatch::FileRotate man page, nor does > it claim to roll it on every invocation. > > You probably need something like a custom file appender for this. > > -- Mike > > Mike Schilli > m...@pe... > > **************************************************************** > The operating companies affiliated with Atradius N.V. (Atradius Group) conduct insurance, debt collection and information services business through their registered (branch) offices in many countries. For information about the main registration details of Atradius Group offices in your country please visit http://global.atradius.com/general-content/legal/legallist.html > > IMPORTANT NOTICE. This e-mail, including any and all attachments, is intended for the addressee or its representative only. It is confidential and may be under legal privilege. Any form of unauthorised use, publication, reproduction, copying or disclosure of the content of this e-mail is not permitted. If you are not the intended recipient of this e-mail and its contents, please notify the sender immediately by reply e-mail and delete this e-mail and all its attachments subsequently. > > Although this e-mail and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and/or opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by Atradius Group companies, either jointly or severally, for any loss or damage arising in any way from its use. E-mail received by Atradius Group can be stored for business purposes. > **************************************** > > > |
From: Mike S. <m...@pe...> - 2009-03-11 17:24:20
|
On Wed, 11 Mar 2009, DAY Roger wrote: > That would work, cheers. I was thinking it'll be fun to write a custom > appender. No doubt, go for it :). -- Mike Mike Schilli m...@pe... > > I'll think on it. > > Roger > > > -----Original Message----- > From: Mike Schilli [mailto:m...@pe...] > Sent: 11 March 2009 15:41 > To: DAY Roger > Cc: Mike Schilli; log4perl MailingList > Subject: RE: [log4perl-devel] rotation on new run of script > > On Wed, 11 Mar 2009, DAY Roger wrote: > >> Which I take to mean it does do invocation-like rollovers. If this >> doesn't work, I'll resort to a custom file appender. > > Actually, you could use something like this: > > log4perl.appender.Logfile = Log::Log4perl::Appender::File > log4perl.appender.Logfile.filename = sub { "log-" . time() . ".log" > } > > to name your logfiles after the current timestamp? > > -- Mike > > Mike Schilli > m...@pe... > >> >> I see what you mean about the valid date patterns. Implement in haste, >> repent at leisure. >> >> Also, apologies for the stupid .sig. I have no control over it. >> >> Roger >> >> -----Original Message----- >> From: Mike Schilli [mailto:m...@pe...] >> Sent: 11 March 2009 07:37 >> To: DAY Roger >> Cc: log4perl MailingList >> Subject: Re: [log4perl-devel] rotation on new run of script >> >> On Tue, 10 Mar 2009, DAY Roger wrote: >> >>> Every time I run a script, I'd like my log-file to roll over. I > invoke >>> Log::Dispatch::FileRotate thusly >>> ... >>> DatePattern => 'HH-dd-yyyy',); >> >> Hmm, this is neither a valid date pattern (yyyy-MM-dd-HH would be >> correct), according to the Log::Dispatch::FileRotate man page, nor > does >> it claim to roll it on every invocation. >> >> You probably need something like a custom file appender for this. >> >> -- Mike >> >> Mike Schilli >> m...@pe... >> >> **************************************************************** >> The operating companies affiliated with Atradius N.V. (Atradius Group) > conduct insurance, debt collection and information services business > through their registered (branch) offices in many countries. For > information about the main registration details of Atradius Group > offices in your country please visit > http://global.atradius.com/general-content/legal/legallist.html >> >> IMPORTANT NOTICE. This e-mail, including any and all attachments, is > intended for the addressee or its representative only. It is > confidential and may be under legal privilege. Any form of unauthorised > use, publication, reproduction, copying or disclosure of the content of > this e-mail is not permitted. If you are not the intended recipient of > this e-mail and its contents, please notify the sender immediately by > reply e-mail and delete this e-mail and all its attachments > subsequently. >> >> Although this e-mail and any attachments are believed to be free of > any virus or other defect that might affect any computer system into > which it is received and/or opened, it is the responsibility of the > recipient to ensure that it is virus free and no responsibility is > accepted by Atradius Group companies, either jointly or severally, for > any loss or damage arising in any way from its use. E-mail received by > Atradius Group can be stored for business purposes. >> **************************************** >> >> >> > |