rev 1786 - in trunk/siesta: . bin lib lib/Siesta lib/Siesta/Plugin t

[prev] [thread] [next] [lurker] [Date index for 2005/01/26]

From: richardc
Subject: rev 1786 - in trunk/siesta: . bin lib lib/Siesta lib/Siesta/Plugin t
Date: 22:15 on 26 Jan 2005
Author: richardc
Date: 2005-01-26 22:15:24 +0000 (Wed, 26 Jan 2005)
New Revision: 1786

Added:
   trunk/siesta/t/log.conf
Modified:
   trunk/siesta/Build.PL
   trunk/siesta/Config.pm.in
   trunk/siesta/bin/nacho
   trunk/siesta/lib/Siesta.pm
   trunk/siesta/lib/Siesta/Message.pm
   trunk/siesta/lib/Siesta/Plugin/Bounce.pm
   trunk/siesta/t/config
Log:
throw out homegrown logging, use Log::Log4perl instead

Modified: trunk/siesta/Build.PL
===================================================================
--- trunk/siesta/Build.PL	2005-01-26 22:06:00 UTC (rev 1785)
+++ trunk/siesta/Build.PL	2005-01-26 22:15:24 UTC (rev 1786)
@@ -20,6 +20,7 @@
         'Email::Simple' => '1.4',
         'Email::LocalDelivery' => '0.05',
         'File::Find::Rule' => '0.20', # appearance of the relative flag
+        'Log::Log4perl' => 0,
         'Mail::Address' => 0,
         'Mail::DeliveryStatus::BounceParser' => 0,
         'MIME::Lite' => 0,

Modified: trunk/siesta/Config.pm.in
===================================================================
--- trunk/siesta/Config.pm.in	2005-01-26 22:06:00 UTC (rev 1785)
+++ trunk/siesta/Config.pm.in	2005-01-26 22:15:24 UTC (rev 1786)
@@ -144,7 +144,9 @@
 
 $config->define( storage_pass => { DEFAULT => undef } );
 
+$config->define( log_config => { DEFAULT => '/usr/local/siesta/log.conf' } );
 
+
 =head1 CREATION
 
 This file is autogenerated from Config.pm.in when you run Build.PL
@@ -157,12 +159,8 @@
     $self->file($file) if -e $file;
 }
 
-
-
 $config->load_from( $CONFIG_FILE );
 
-
-
 sub storage {
     my $self = shift;
     if (@_) {

Modified: trunk/siesta/bin/nacho
===================================================================
--- trunk/siesta/bin/nacho	2005-01-26 22:06:00 UTC (rev 1785)
+++ trunk/siesta/bin/nacho	2005-01-26 22:15:24 UTC (rev 1786)
@@ -47,7 +47,8 @@
     exit;
 }
 
-Siesta->log("nacho invoked by $< $> args\n" . Dump \@ARGV);
+our $logger = Log::Log4perl->get_logger;
+$logger->info("$<:$> invoked: nacho ", shell_quote @ARGV);
 
 tie my %commands, 'Tie::IxHash';
 

Modified: trunk/siesta/lib/Siesta/Message.pm
===================================================================
--- trunk/siesta/lib/Siesta/Message.pm	2005-01-26 22:06:00 UTC (rev 1785)
+++ trunk/siesta/lib/Siesta/Message.pm	2005-01-26 22:15:24 UTC (rev 1786)
@@ -8,6 +8,8 @@
 use base qw( Email::Simple Class::Accessor::Fast );
 __PACKAGE__->mk_accessors(qw( plugins ));
 
+our $logger = Log::Log4perl->get_logger;
+
 =head1 NAME
 
 Siesta::Message - a message in the system
@@ -91,7 +93,7 @@
     $new->header_set( 'In-Reply-To', $self->header( 'Message-Id' ) );
 
     $new->send;
-    Siesta->log("Message->reply sending" . $new->as_string, 10);
+    $logger->debug("sending\n", $new->as_string);
 }
 
 =head2 send
@@ -145,7 +147,7 @@
         # SIESTA_NON_STOP is used by 20fullsend.t to ensure
         # excercising of everything. it means "run the next plugin,
         # even if the last one said to stop"
-        Siesta->log("... doing " . $plugin->name, 1);
+        $logger->debug( "calling the ", $plugin->name, " plugin" );
         return if $plugin->process($self) && !$ENV{SIESTA_NON_STOP};
     }
 }

Modified: trunk/siesta/lib/Siesta/Plugin/Bounce.pm
===================================================================
--- trunk/siesta/lib/Siesta/Plugin/Bounce.pm	2005-01-26 22:06:00 UTC (rev 1785)
+++ trunk/siesta/lib/Siesta/Plugin/Bounce.pm	2005-01-26 22:15:24 UTC (rev 1786)
@@ -4,6 +4,8 @@
 use base 'Siesta::Plugin';
 use Mail::DeliveryStatus::BounceParser;
 
+our $logger = Log::Log4perl->get_logger;
+
 # suggested usage  set_plugins( bounce => qw( Bounce ) );
 
 sub description {
@@ -21,11 +23,12 @@
     my $bounce = Mail::DeliveryStatus::BounceParser->new( $mail->as_string );
     my @addresses = grep { $_ } map { $_->get('email') } $bounce->reports;
 
-    Siesta->log("bounce: ". $list->name . " " . join (', ', @addresses));
+    $logger->info( "bounce for '", $list->name, "' from ",
+                   join ', ', @addresses );
 
     if (grep { $_ eq $list->owner->email } @addresses) {
         # deep deep badness
-        Siesta->log("holy shit, a listadmins mail is bouncing, so we can't tell them about it!");
+        $logger->fatal("holy shit, a listadmins mail is bouncing, so we can't tell them about it!");
         return;
     }
     $mail->reply( to      => $list->owner->email,

Modified: trunk/siesta/lib/Siesta.pm
===================================================================
--- trunk/siesta/lib/Siesta.pm	2005-01-26 22:06:00 UTC (rev 1785)
+++ trunk/siesta/lib/Siesta.pm	2005-01-26 22:15:24 UTC (rev 1786)
@@ -6,12 +6,14 @@
 use Template;
 use Carp qw(croak);
 use Log::Log4perl;
-Log::Log4perl::init('/usr/local/siesta/log.conf');
 
 use Siesta::Config;
 use Siesta::List;
 use Siesta::Message;
 
+Log::Log4perl::init( $config->log_config );
+
+our $logger = Log::Log4perl->get_logger;
 our $VERSION = '0.66_01';
 
 =head1 NAME
@@ -32,7 +34,7 @@
     my $storage = delete $args{storage};
 
     my $self = bless {}, $class;
-    $self->log("instantiated a Siesta", 7);
+    $logger->debug("instantiated a Siesta");
     $self;
 }
 
@@ -58,7 +60,8 @@
     my $mail   = Siesta::Message->new( $args{mail} );
     my $list   = Siesta::List->load( $args{list} );
 
-    $self->log("processing $action", 1);
+    $logger->info( "processing '$action' pipeline for '",  $list->name,
+                   "' list. message-id '", $mail->header('message-id'), "'" );
     $mail->plugins( [ $list->plugins( $action ) ] );
     $mail->process;
 }
@@ -97,38 +100,7 @@
     $sender = $class->new(@_);
 }
 
-=head2 ->log ($message, $level)
 
-Log message as long as level is below the value set in
-I<$config->log_level>;
-
-The lower the log level, the more important the error.
-
-The default is 3.
-
-=cut
-
-my $logger;
-
-sub log {
-    my $self     = shift;
-    my $message  = shift
-      or croak "need a message to log";
-
-    my $level = shift || $config->log_level;
-
-    unless ($logger) {
-        my $file = $config->log_path;
-        open $logger, ">>$file"
-          or die "Couldn't open file $file for appending\n";
-    }
-
-    my $date = localtime;
-    print $logger "$date $message $level\n"
-      if $level >= $config->log_level;
-}
-
-
 =head2 ->available_plugins
 
 Return the name of every plugin on the system.

Modified: trunk/siesta/t/config
===================================================================
--- trunk/siesta/t/config	2005-01-26 22:06:00 UTC (rev 1785)
+++ trunk/siesta/t/config	2005-01-26 22:15:24 UTC (rev 1786)
@@ -1,2 +1,4 @@
 messages = messages
-log_path = t/temp_error
+log_config = t/log.conf
+archive = t/root/archive
+root   = t/root

Added: trunk/siesta/t/log.conf
===================================================================
--- trunk/siesta/t/log.conf	2005-01-26 22:06:00 UTC (rev 1785)
+++ trunk/siesta/t/log.conf	2005-01-26 22:15:24 UTC (rev 1786)
@@ -0,0 +1,6 @@
+log4perl.rootLogger = DEBUG, FILE
+
+log4perl.appender.FILE          = Log::Log4perl::Appender::File
+log4perl.appender.FILE.filename = siesta.log
+log4perl.appender.FILE.layout   = Log::Log4perl::Layout::PatternLayout
+log4perl.appender.FILE.layout.ConversionPattern = [%d] %P %p %M %m%n

Generated at 23:00 on 26 Jan 2005 by mariachi 0.52