[Jifty-commit] r4587 - in jifty/trunk: lib/Jifty/Plugin

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Nov 30 16:59:45 EST 2007


Author: sartak
Date: Fri Nov 30 16:59:45 2007
New Revision: 4587

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Plugin/Recorder.pm

Log:
 r48448 at onn:  sartak | 2007-11-30 16:59:38 -0500
 Cache the log handle so the file isn't opened every hit


Modified: jifty/trunk/lib/Jifty/Plugin/Recorder.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Recorder.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/Recorder.pm	Fri Nov 30 16:59:45 2007
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 use base qw/Jifty::Plugin Class::Data::Inheritable/;
-__PACKAGE__->mk_accessors(qw/start path/);
+__PACKAGE__->mk_accessors(qw/start path handle/);
 
 use Time::HiRes 'time';
 use YAML;
@@ -31,6 +31,8 @@
 
     $self->start(time);
     $self->path($args{path});
+
+    $self->handle($self->get_handle);
 }
 
 =head2 before_request
@@ -48,19 +50,25 @@
     my $request = { cgi => $cgi, ENV => \%ENV, time => $delta };
     my $yaml = YAML::Dump($request);
 
-    my $name = sprintf '%s/%d-%d.log',
+    print { $self->handle } $yaml;
+}
+
+sub get_handle {
+    my $self = shift;
+
+    my $name = sprintf '%s/requests-%d-%d.log',
                 $self->path,
                 $self->start,
                 $$;
 
-    open my $handle, '>>', $name or do {
-        Jifty->log->error("Unable to open $name for appending: $!");
+    open my $handle, '>', $name or do {
+        Jifty->log->error("Unable to open $name for writing: $!");
         return;
     };
 
-    print $handle $yaml;
+    Jifty->log->info("Logging all HTTP requests to $name.");
 
-    close $handle;
+    return $handle;
 }
 
 =head1 NAME


More information about the Jifty-commit mailing list