Subject: | PATCH: Add DevPopup support |
Am already using CAP::DevPopup in my apps right now for testing, and
wanted to integrate a list of items logged via CAP::LogDispatch.
So... I patched CAP::LogDispatch to add support for CAP::DevPopup.
With the attached patch in place, you'll find a new "Log::Dispatch"
item in your DevPopup windows that shows you a list of all of the
items that were logged by the App in this HTTP request.
Only gotcha is that you've got to make sure that you load
CAP::DevPopup before you load CAP::LogDispatch, otherwise the hooks to
capture log data aren't set up.
Subject: | cap-logdispatch-devpopup-support.diff |
--- LogDispatch.pm.orig 2006-10-12 14:47:39.613612600 -0700
+++ LogDispatch.pm 2006-10-12 14:47:39.609612390 -0700
@@ -24,6 +24,7 @@
*{"${callpkg}::$sym"} = \&{$sym};
}
$callpkg->log_config(@_) if @_;
+ $callpkg->add_callback( 'devpopup_report', \&_devpopup_report ) if ($callpkg->can('devpopup'));
}
sub log {
@@ -77,6 +78,20 @@
$log->add( Log::Dispatch::Screen->new( %options ) );
}
_set_object($frompkg||$self, $log);
+
+ # CAP::DevPopup support
+ if (UNIVERSAL::can($self, 'devpopup')) {
+ my %options = (
+ 'name' => 'DevPopup',
+ 'min_level' => 'debug',
+ 'filename' => '/dev/null',
+ 'callbacks' => sub {
+ my %args = @_;
+ push( @{$self->{LOG_DISPATCH_DEVPOPUP_HISTORY}}, [$args{level}, $args{message}] );
+ },
+ );
+ $log->add( Log::Dispatch::File->new(%options) );
+ }
}
return $log;
@@ -206,6 +221,30 @@
return;
}
+sub _devpopup_report {
+ my $self = shift;
+ my $r=0;
+ my $history = join $/, map {
+ $r=1-$r;
+ qq(<tr class="@{[$r?'odd':'even']}"><td valign="top">$_->[0]</td><td>$_->[1]</td></tr>)
+ }
+ @{$self->{LOG_DISPATCH_DEVPOPUP_HISTORY}};
+ $self->devpopup->add_report(
+ title => "Log::Dispatch",
+ summary => "All entries logged via Log::Dispatch",
+ report => qq(
+ <style type="text/css">
+ tr.even{background-color:#eee}
+ </style>
+ <div style="font-size: 80%">
+ <table>
+ <thead><tr><th>Level</th><th>Message</th></tr></thead>
+ <tbody>$history</tbody>
+ </table>
+ </div>
+ ),
+ );
+}
1;
__END__