From: Lee C. <lec...@ya...> - 2004-08-23 22:37:21
Attachments:
File.pm.patch
|
Hello Everyone, I have run across a slight problem or a request for a new feature with the Log::Log4perl::Appender::File.pm module. I asked for a filename method to access the 'filename' attribute but now I want to override the 'filename' attribute in a child module (what is the correct OO term for something down the tree in inheritence...?) The problem is that the 'file_open' method/sub uses the attribute not the method so if I override 'filename' method it doesn't get used by the 'file_open'. I have patched (and included) diff for the 'File.pm' to use the method instead of the attribute. I could have override the 'file_open' method but that is more than the three lines to override the 'filename' method... Yes I am very lazy. ;) Let me know if this sounds odd or if I'm asking for wildly bad things? Thanks and keep up the great work, Lee __________________________________ Do you Yahoo!? Yahoo! Mail - You care about security. So do we. http://promotions.yahoo.com/new_mail |
From: Mike S. <m...@pe...> - 2004-08-24 00:46:13
|
Lee Carmichael wrote on 8/23/2004, 3:37 PM: > I have run across a slight problem or a request for a > new feature with the Log::Log4perl::Appender::File.pm > module. I asked for a filename method to access the > 'filename' attribute but now I want to override the > 'filename' attribute in a child module (what is the > correct OO term for something down the tree in > inheritence...?) I typically use the term "derived class". > The problem is that the 'file_open' > method/sub uses the attribute not the method so if I > override 'filename' method it doesn't get used by the > 'file_open'. I have patched (and included) diff for > the 'File.pm' to use the method instead of the > attribute. I could have override the 'file_open' > method but that is more than the three lines to > override the 'filename' method... Yes I am very lazy. > ;) Can you provide more details on what the derived class will be provide differently than the base class? If you're overriding filename(), you probably also have to override the constructor, which doesn't leave much base class functionality left. -- -- Mike Mike Schilli m...@pe... |
From: Lee C. <lec...@ya...> - 2004-08-24 13:25:14
|
Hello Mike, > I typically use the term "derived class". As yes. It was the end of a long day. Thank you. > Can you provide more details on what the derived > class will be provide > differently than the base class? If you're > overriding filename(), you > probably also have to override the constructor, > which doesn't leave much > base class functionality left. Sure. Basically I have one derived class that creates a sub directory to put the logfile in if a MDC key => value have been set. There has been a request by our ops folks to make the logs use a daily date format. My plan was to leave the sub directory class alone and just derive another class from it where I used the 'Date::Format' modules 'time2str' to allow the format to be set in the configuration then override the 'filename' method to call the 'time2str' function for the name so this was continually updated with the correct date instead of ever setting/updating the 'filename' attribute. This way the filename value is always the log pattern not the actual date but the filename when used by 'file_open' is the real date. It does mean I have to make a constructor but this inits one attribute for my class and calls the constructor for the super class. I thought about doing it with the by overriding the log method and just continuely updating the logfile with the 'file_switch' but it seemed just as easy to do it this way. I have attached the second class, it isn't very long. In this one, I am accessing the internal 'filename' attribute but I meant to update this to use my own value. sub new { my($class, %options) = @_; my $self = $class->SUPER::new(%options); $self->{'ofilename'} = $options{'filename'}; bless($self, $class); return($self); } sub filename { my $self = shift; ## the 'filename' here could be a differ attribute for only this class return time2str($self->{filename}, time()); } Thanks for your time, Lee _______________________________ Do you Yahoo!? Win 1 of 4,000 free domain names from Yahoo! Enter now. http://promotions.yahoo.com/goldrush |
From: Mike S. <m...@pe...> - 2004-08-24 17:34:22
|
Lee Carmichael wrote on 8/24/2004, 6:25 AM: > There has been a request by our > ops folks to make the logs use a daily date format. Hmm, it looks like your requirement of a log file name based on the current date could be met by the "Rolling File Appender", see this FAQ: http://log4perl.sourceforge.net/d/Log/Log4perl/FAQ.html#923b3 However, if you still want to derive a class from L4p::Appender::File (or from your directory class), here's a couple of comments: Currently, there's two different methods in Log::Log4perl::Appender::File which are setting/modifying the filename: The constructor new() and the switch_file() method. Both take the file name as a parameter. Changing the internal {filename} attribute has no effect, it won't log to a different file unless switch_file() is called. So, I would recommend that the derived class doesn't override file_open() or filename(), but comes with its own constructor, calling the base class constructor with the desired file name. If you need to switch the name during runtime, I suggest overriding log() and using switch_file() if desired. Would this be an option? -- -- Mike Mike Schilli m...@pe... |
From: Lee C. <lec...@ya...> - 2004-08-24 18:51:12
|
Hello Mike, > switch the name during runtime, I suggest overriding > log() and using > switch_file() if desired. Would this be an option? Thanks for the advice. I think I will try overriding the 'log' method and use the 'switch_file' method. It just means I need to be more careful about verifying the date has actually changed before switching the log file because I would guess there is a performance cost. Thanks again, Lee __________________________________ Do you Yahoo!? Yahoo! Mail Address AutoComplete - You start. We finish. http://promotions.yahoo.com/new_mail |
From: Mike S. <m...@pe...> - 2004-08-24 20:25:43
|
Lee Carmichael wrote on 8/24/2004, 11:51 AM: > It > just means I need to be more careful about verifying > the date has actually changed before switching the log > file because I would guess there is a performance > cost. I think Log::Dispatch::FileRotate does that in a fairly efficient manner. You could probably get a couple of ideas from looking at its source code. -- -- Mike Mike Schilli m...@pe... |