From: Roger Y. <rog...@ey...> - 2004-12-03 17:01:45
|
Dear Sirs, I stumbled across your logging suite and have headed your advice by retiring my old debug routine. It has many features that I had only considered incorporating in the past. I love it! However, I did encounter a problem when I tried to use ActiveState's perlapp compiler; turns out none of the modules specified in the configuration file (appenders/filters/layouts) were being compiled in since the 'require' was being handled via an eval. Therefore, I had to make the following modifications to get around it. * Added the appenders, filters, and layouts as additional modules to be compiled in. (The easy part.) * Modified Log::Log4perl::Config to handle abbreviated layout names outside of the call to Log::Log4perl::Util::module_available (see diff below). * Modified Log::Log4perl::Util::module_available to always return true (see diff below). Although these were just quick fixes, it might be worth either including the appenders/filters/layouts as standard require/use statements or providing a different mechanism that will allow compilers to identify the required modules normally. Also, I have included file compression (using IO::Zlib) into the Log::Log4perl::Appender::file (see diff below). Sincerely, Roger Yager Software Engineer Eye Street Software Corporation Email: rog...@ey... Cell: 703-585-2735 ################################# Begin Config file Diffs ################################# $ diff -c /cygdrive/c/Downloads/Development/perl/Log-Log4perl-Config*.pm *** /cygdrive/c/Downloads/Development/perl/Log-Log4perl-Config-ry.pm Fri Dec 3 11:35:27 2004 --- /cygdrive/c/Downloads/Development/perl/Log-Log4perl-Config.pm Fri Dec 3 11:28:14 2004 *************** *** 461,468 **** } } - $layout_class = ($layout_class !~ /::/) ? "Log::Log4perl::Layout::$layout_class" : $layout_cla - eval "require $layout_class" or die "Require to $layout_class failed ($!)"; --- 461,466 ---- ################################## End Config file Diffs ################################## ################################## Begin Util file Diffs ################################## $ diff -c /cygdrive/c/Downloads/Development/perl/Log-Log4perl-Util.pm Util.pm *** /cygdrive/c/Downloads/Development/perl/Log-Log4perl-Util.pm Fri Dec 3 11:28:35 2004 --- Util.pm Fri Dec 3 11:29:44 2004 *************** *** 10,15 **** --- 10,16 ---- ################################################## my($full_name) = @_; + return(1); my $relpath = File::Spec->catfile(split /::/, $full_name) . '.pm'; foreach my $dir (@INC) { ################################### End Util file Diffs ################################## ################################ Begin Appender file Diffs ############################### # Note: modifications were made to version 0.48 so the diff was between 0.48 and 0.49 # $ diff -c /cygdrive/c/Downloads/Development/perl/Log-Log4perl-Appender-File.pm File.pm *** /cygdrive/c/Downloads/Development/perl/Log-Log4perl-Appender-File.pm Fri Dec 3 10:41:01 2004 --- File.pm Fri Dec 3 10:47:18 2004 *************** *** 2,7 **** --- 2,8 ---- package Log::Log4perl::Appender::File; ################################################## + use IO::Zlib; use warnings; use strict; *************** *** 11,29 **** my($class, @options) = @_; my $self = { ! name => "unknown name", ! autoflush => 1, ! mode => "append", @options, }; die "Mandatory parameter 'filename' missing" unless exists $self->{filename}; bless $self, $class; ! # This will die() if it fails ! $self->file_open(); return $self; } --- 12,43 ---- my($class, @options) = @_; my $self = { ! name => "unknown name", ! autoflush => 1, ! mode => "append", ! 'compression' => 0, ! 'compressionLevel' => 9, @options, }; die "Mandatory parameter 'filename' missing" unless exists $self->{filename}; + $self->{'compression'} = Log::Log4perl::Config::boolean_to_perlish( + $self->{'compression'}); + bless $self, $class; ! # This will die() if it fails ! if ( $self->{'compression'} ) { ! if ( $self->{'mode'} eq "pipe" ) { ! die("Pipe not supported with compression!"); ! } ! ! $self->compressed(); ! } else { ! $self->file_open(); ! } return $self; } *************** *** 58,63 **** --- 72,109 ---- } ################################################## + sub compressed { # Compressed files + ################################################## + my($self) = shift; + my($mode); + my($addedExtension) = 0; + my(%params); + + # Establish the mode + $mode = join("", substr($self->{'mode'}, 0, 1), "b", + $self->{'compressionLevel'}); + + # Add a gz extension if necessary + if ( $self->{'filename'} !~ /\.gz$/ ) { + $addedExtension = 1; + $self->{'filename'} .= ".gz"; + } + + # Establish the handle + $self->{'fh'} = new IO::Zlib; + if (! $self->{'fh'}->open($self->{'filename'}, $mode)) { + die("Unabele to open compressed file: $self->{filename}!"); + } + + # Include a message about the modification of the filename + if ( $addedExtension ) { + $params{'message'} = "Filename $self->{filename} missing " . + "gz extension. Extension .gz has been added."; + #$self->log(%params); + } + } + + ################################################## sub file_close { ################################################## my($self) = @_; *************** *** 115,123 **** use Log::Log4perl::Appender::File; my $app = Log::Log4perl::Appender::File->new( ! filename => 'file.log', ! mode => 'append', ! autoflush => 1, ); $file->log(message => "Log me\n"); --- 161,171 ---- use Log::Log4perl::Appender::File; my $app = Log::Log4perl::Appender::File->new( ! filename => 'file.log', ! compression => true, ! compressionLevel => 5, ! mode => 'append', ! autoflush => 1, ); $file->log(message => "Log me\n"); *************** *** 141,149 **** Upon destruction of the object, the filehandle to access the file is flushed and closed. If you want to switch over to a different logfile, use the C<switch_file($newfile)> method which will first close the old ! file handle and then open a one to the new file specified. Design and implementation of this module has been greatly inspired by Dave Rolsky's C<Log::Dispatch> appender framework. --- 189,202 ---- Upon destruction of the object, the filehandle to access the file is flushed and closed. + Setting the compression attribute to true will allow the log file to be + written in compressed form using IO::Zlib. Specifying the compressionLevel + attribute will determine the level of compression used. By default the + maximum compression level of 9 will be utilized. + If you want to switch over to a different logfile, use the C<switch_file($newfile)> method which will first close the old ! file handle and then open the new file specified. Design and implementation of this module has been greatly inspired by Dave Rolsky's C<Log::Dispatch> appender framework. ################################ End Appender file Diffs ############################### |