Split code to log stats report (RT#127392)
Robert Rothenberg [Wed, 17 Oct 2018 11:36:16 +0000 (12:36 +0100)]
Added log_stats method that does the actual logging of the
stats.  This allows the stats to be enabled, but the logging
of the stats report to be overridden or modified.

Changes
lib/Catalyst.pm

diff --git a/Changes b/Changes
index c9534ca..4b488be 100644 (file)
--- a/Changes
+++ b/Changes
@@ -2,6 +2,7 @@
 
   - Fix emitting warnings when REMOTE_ADDR is undefined (RT#113388)
   - Fix $c->req->hostname empty for IPv6 clients (RT#75731)
+  - split code to log stats report into a separate log_stats method (RT#127392)
 
 5.90122 - 2018-11-03
   - releasing as stable
index 2258ae8..a2274f1 100644 (file)
@@ -2196,16 +2196,27 @@ sub finalize {
 
     $c->log_response;
 
-    if ($c->use_stats) {
-        my $elapsed = $c->stats->elapsed;
-        my $av = $elapsed == 0 ? '??' : sprintf '%.3f', 1 / $elapsed;
-        $c->log->info(
-            "Request took ${elapsed}s ($av/s)\n" . $c->stats->report . "\n" );
-    }
+    $c->log_stats if $c->use_stats;
 
     return $c->response->status;
 }
 
+=head2 $c->log_stats
+
+Logs statistics.
+
+=cut
+
+sub log_stats {
+    my $c = shift;
+
+    my $elapsed = $c->stats->elapsed;
+    my $av = $elapsed == 0 ? '??' : sprintf '%.3f', 1 / $elapsed;
+    $c->log->info(
+        "Request took ${elapsed}s ($av/s)\n" . $c->stats->report . "\n" );
+}
+
+
 =head2 $c->finalize_body
 
 Finalizes body.
@@ -5011,6 +5022,8 @@ revmischa: Mischa Spiegelmock <revmischa@cpan.org>
 
 Robert Sedlacek <rs@474.at>
 
+rrwo: Robert Rothenberg <rrwo@cpan.org>
+
 SpiceMan: Marcel Montes
 
 sky: Arthur Bergman