Icon for Dimension.orgIcon for TalentIcon for ToolsIcon for Doorways.org
Icon for ToolsIcon for Perl Tools

MMAgic Demo: MMAgic/Log/Apache.pm Source File

  • Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

MMAgic/Log/Apache.pm

Go to the documentation of this file.
00001 package MMAgic::Log::Apache;
00002 #
00003 # MMAgic/Log/Apache.pm
00004 #
00005 #   Log stream that redirects to Apache logging functions.
00006 #
00007 
00008 use     strict;
00009 use     warnings;
00010 use     UNIVERSAL   qw(isa);
00011 
00012 use     Apache::Log;
00013 use     Apache::ServerUtil;
00014 
00015 use     MMAgic::Log;
00016 
00017 our     @ISA = qw(MMAgic::Log);
00018 
00019 ###########################################################################
00020 ###########################################################################
00021 sub new         #
00022 #
00023     {
00024     bless { code => 'T' }, shift
00025     }
00026 
00027 ###########################################################################
00028 ###########################################################################
00029 sub flush   # $self
00030 # Flush pending output.
00031 #   Perl doesn't directly support any flushing functionality,
00032 #   it makes do with autoflush, but we have string buffering to flush:
00033 #
00034     {
00035     my  $self = shift;
00036 
00037     if ($self->{useStr})
00038         {
00039         # After this data will go directly to the
00040         #   normal output:
00041         delete $self->{useStr};
00042 
00043         # Process any existing string data:
00044         if (defined $self->{string} && length  $self->{string})
00045             {
00046             map {
00047                 $self->process($_)
00048                 } split(/\n/, $self->{string});
00049             }
00050 
00051         # OK, we can jettison this now:
00052         delete $self->{string};
00053         }
00054     }
00055 
00056 ###########################################################################
00057 sub process # $self, @list
00058 # Print or store the specified items.
00059 #   We do ASSUME here that newlines are always separate strings,
00060 #   which should be true given the way MMAgic::Output works.
00061 #
00062     {
00063     my  $self = shift;
00064 
00065 #   lock($self);
00066 
00067     # Look for string first to handle buffering cases:
00068 
00069     if ($self->{useStr})
00070         {
00071         $self->{string} .= join '', @_;
00072         }
00073     
00074     else
00075         {
00076         my  $log  = Apache->server->log;
00077 
00078         map {
00079             if ($_ ne "\n")
00080                 {
00081                 $self->{_apLine_} .= $_;
00082                 }
00083             
00084             elsif ($self->{_apLine_})
00085                 {
00086                 my  $code = $self->{_apLine_} =~ s/^\s*\[(.)\]\s// ? $1 : ' ';
00087     
00088                 if ($code eq 'C')
00089                     {
00090                     $log->crit($self->{_apLine_});
00091                     }
00092                 
00093                 elsif ($code eq 'E')
00094                     {
00095                     $log->error($self->{_apLine_});
00096                     }
00097                 
00098                 elsif ($code eq 'W')
00099                     {
00100                     $log->warn($self->{_apLine_});
00101                     }
00102                 
00103                 elsif ($code eq 'I')
00104                     {
00105                     $log->notice($self->{_apLine_});
00106                     }
00107                 
00108                 else
00109                     {
00110                     $log->info($self->{_apLine_});
00111                     }
00112 
00113                 delete $self->{_apLine_};
00114                 }
00115             } @_;
00116         }
00117     
00118     return $self;
00119     }
00120 
00121 ###########################################################################
00122 sub timestamp   # [ $clasSelf ] [ $when ]
00123 #
00124     {
00125     ''
00126     }
00127 
00128 1

Generated on Mon Dec 27 2010 15:15:42 for MMAgic Demo by  doxygen 1.7.1

www.dimension.org logo

(C)opyright 1998 - 2012 Dimension.org

WebMaster