[Jifty-commit] r4670 - in jifty/trunk: lib/Jifty lib/Jifty/Plugin
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Thu Dec 13 03:41:54 EST 2007
Author: sartak
Date: Thu Dec 13 03:41:54 2007
New Revision: 4670
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Handler.pm
jifty/trunk/lib/Jifty/Plugin/Recorder.pm
Log:
r49010 at onn: sartak | 2007-12-13 03:39:52 -0500
Recorder: record the current user ID so we can still playback (to some degree) without the sessions table
Modified: jifty/trunk/lib/Jifty/Handler.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Handler.pm (original)
+++ jifty/trunk/lib/Jifty/Handler.pm Thu Dec 13 03:41:54 2007
@@ -244,6 +244,9 @@
# Return from the continuation if need be
Jifty->web->request->return_from_continuation;
$self->dispatcher->handle_request();
+
+ $self->call_trigger('before_cleanup', $args{cgi});
+
$self->cleanup_request();
}
Modified: jifty/trunk/lib/Jifty/Plugin/Recorder.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Recorder.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Recorder.pm Thu Dec 13 03:41:54 2007
@@ -2,7 +2,7 @@
use strict;
use warnings;
use base qw/Jifty::Plugin Class::Data::Inheritable/;
-__PACKAGE__->mk_accessors(qw/start path loghandle/);
+__PACKAGE__->mk_accessors(qw/start path loghandle print_current_user/);
use Time::HiRes 'time';
use Jifty::Util;
@@ -33,6 +33,10 @@
Jifty::Handler->add_trigger(
before_request => sub { $self->before_request(@_) }
);
+
+ Jifty::Handler->add_trigger(
+ before_cleanup => sub { $self->before_cleanup }
+ );
}
=head2 before_request
@@ -47,17 +51,45 @@
my $handler = shift;
my $cgi = shift;
+ $self->print_current_user(0);
+
eval {
my $delta = time - $self->start;
my $request = { cgi => nfreeze($cgi), ENV => \%ENV, time => $delta };
my $yaml = Jifty::YAML::Dump($request);
print { $self->get_loghandle } $yaml;
+ $self->print_current_user(1);
};
Jifty->log->error("Unable to append to request log: $@") if $@;
}
+=head2 before_cleanup
+
+Append the current user to the request log. This isn't done in one fell swoop
+because if the server explodes during a request, we would lose the request's
+data for logging.
+
+This, strictly speaking, isn't necessary. But we don't always want to lug the
+sessions table around, so this gets us most of the way there.
+
+C<print_current_user> is checked to ensure that we don't append the current
+user if the current request couldn't be logged for whatever reason (perhaps
+a serialization error?).
+
+=cut
+
+sub before_cleanup {
+ my $self = shift;
+
+ if ($self->print_current_user) {
+ eval {
+ print { $self->get_loghandle } "current_user: " . (Jifty->web->current_user->id || 0) . "\n";
+ };
+ }
+}
+
=head2 get_loghandle
Creates the loghandle. The created file is named C<PATH/BOOTTIME-PID.log>.
More information about the Jifty-commit
mailing list