/[meteor]/googlecode.com/svn/trunk/Meteor/Syslog.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /googlecode.com/svn/trunk/Meteor/Syslog.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 9 by andrew.betts, Fri Dec 8 16:52:58 2006 UTC revision 62 by andrew.betts, Thu Nov 27 00:33:21 2008 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl -w  #!/usr/bin/perl -w
2  ###############################################################################  ###############################################################################
3  #   Meteor  #   Meteor
4  #   An HTTP server for the 2.0 web  #   An HTTP server for the 2.0 web
5  #   Copyright (c) 2006 contributing authors  #   Copyright (c) 2006 contributing authors
6  #  #
7  #   Subscriber.pm  #   Subscriber.pm
8  #  #
9  #       Description:  #       Description:
10  #       Convenience interface to syslog  #       Convenience interface to syslog
11  #  #
12  ###############################################################################  ###############################################################################
13  #  #
14  #   This program is free software; you can redistribute it and/or modify it  #   This program is free software; you can redistribute it and/or modify it
15  #   under the terms of the GNU General Public License as published by the Free  #   under the terms of the GNU General Public License as published by the Free
16  #   Software Foundation; either version 2 of the License, or (at your option)  #   Software Foundation; either version 2 of the License, or (at your option)
17  #   any later version.  #   any later version.
18  #  #
19  #   This program is distributed in the hope that it will be useful, but WITHOUT  #   This program is distributed in the hope that it will be useful, but WITHOUT
20  #   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or  #   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  #   FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for  #   FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22  #   more details.  #   more details.
23  #  #
24  #   You should have received a copy of the GNU General Public License along  #   You should have received a copy of the GNU General Public License along
25  #   with this program; if not, write to the Free Software Foundation, Inc.,  #   with this program; if not, write to the Free Software Foundation, Inc.,
26  #   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  #   59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27  #  #
28  #   For more information visit www.meteorserver.org  #   For more information visit www.meteorserver.org
29  #  #
30  ###############################################################################  ###############################################################################
31    
32  package Meteor::Syslog;  package Meteor::Syslog;
33  ###############################################################################  ###############################################################################
34    
35          use strict;          use strict;
36          use Sys::Syslog;          use Sys::Syslog;
37                    
38  ###############################################################################  ###############################################################################
39  # Configuration  # Configuration
40  ###############################################################################  ###############################################################################
41    
42          $Meteor::Syslog::DEFAULT_FACILITY='daemon';          $Meteor::Syslog::DEFAULT_FACILITY='daemon';
43            
44          $Meteor::Syslog::_open=0;               # set to 1 by _open          $Meteor::Syslog::_lasttimestamp=0;
45                    $Meteor::Syslog::_lasttimestring="";
46  ###############################################################################          $Meteor::Syslog::_open=0;               # set to 1 by _open
47  # Implementation          
48  ###############################################################################  ###############################################################################
49  sub ::syslog {  # Implementation
50            ###############################################################################
51          if($::CONF{'Debug'})  sub ::syslog {
52          {          
53                  my $priority=shift;          my $debug=$::CONF{'Debug'};
54                  my $format=shift;          
55                            my $priority=shift;
56                  $format=~s/\%m/$!/g;          return if($priority eq 'debug' && !$debug);
57                            
58                  print STDERR "$::PGM($priority): ";          my $format=shift;
59                  print STDERR sprintf($format,@_);          my @args=@_;
60                  print STDERR "\n" unless(substr($format,-1) eq "\n");          
61                            if($format eq '')
62                  return;          {
63          }                  my $txt=join("\t",@args);
64          else                  $format='%s';
65          {                  @args=($txt);
66                  # No expensive syslog calls for debug!          }
67                  return if($_[0] eq 'debug');          
68          }          my $facility=$::CONF{'SyslogFacility'} || $Meteor::Syslog::DEFAULT_FACILITY;
69                    
70          unless($Meteor::Syslog::_open)          if($debug || $facility eq 'none')
71          {          {
72                  my $facility=$::CONF{'SyslogFacility'} || $Meteor::Syslog::DEFAULT_FACILITY;                  $format=~s/\%m/$!/g;
73                  openlog($::PGM,0,$facility);                                  
74                  $Meteor::Syslog::_open=1;                  my $time = time;
75          }                  if ($::CONF{'LogTimeFormat'} ne 'unix') {
76                                    if ($Meteor::Syslog::_lasttimestamp != time) {
77          syslog(@_);                                  $Meteor::Syslog::_lasttimestring = localtime(time);
78  }                                  $Meteor::Syslog::_lasttimestamp = time;
79                            }
80  sub myWarn {                          $time = $Meteor::Syslog::_lasttimestring;
81          local $SIG{'__DIE__'}='';                  }
82          local $SIG{'__WARN__'}='';  
83                            print STDERR "$time\t$priority\t";
84          &::syslog('warning',$_[0]);                  print STDERR sprintf($format,@args);
85  }                  print STDERR "\n" unless(substr($format,-1) eq "\n");
86                    
87  sub myDie {                  return;
88          local $SIG{'__DIE__'}='';          }
89          local $SIG{'__WARN__'}='';          
90                            unless($Meteor::Syslog::_open)
91          my $inEval=0;          {
92          my $i=0;                  my $facility=$::CONF{'SyslogFacility'} || $Meteor::Syslog::DEFAULT_FACILITY;
93          my $sub;                  openlog($::PGM,0,$facility);
94          while((undef,undef,undef,$sub)=caller(++$i))                  $Meteor::Syslog::_open=1;
95          {          }
96                  $inEval=1, last if $sub eq '(eval)';          
97          }          syslog($priority,$format,@args);
98            }
99          unless($inEval)  
100          {  sub myWarn {
101                  &::syslog('err',$_[0]);          local $SIG{'__DIE__'}='';
102                  $Meteor::Socket::NO_WARN_ON_CLOSE=1;          local $SIG{'__WARN__'}='';
103                  exit;          
104          }          &::syslog('warning',$_[0]);
105  }  }
106    
107  1;  sub myDie {
108            local $SIG{'__DIE__'}='';
109            local $SIG{'__WARN__'}='';
110                    
111            my $inEval=0;
112            my $i=0;
113            my $sub;
114            while((undef,undef,undef,$sub)=caller(++$i))
115            {
116                    $inEval=1, last if $sub eq '(eval)';
117            }
118            
119            unless($inEval)
120            {
121                    &::syslog('err',$_[0]);
122                    $Meteor::Socket::NO_WARN_ON_CLOSE=1;
123                    exit;
124            }
125    }
126    
127    1;
128  ############################################################################EOF  ############################################################################EOF

Legend:
Removed from v.9  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.26