From 24996a35516a9b3d29ad5cd7a1f78b497ddd9904 Mon Sep 17 00:00:00 2001
From: Mark Harrison <mark@mivok.net>
Date: Wed, 28 Nov 2012 16:32:51 -0500
Subject: [PATCH] Limit the number of error lines that can be contained in
 errstring

---
 lib/Core/Log.pm | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/lib/Core/Log.pm b/lib/Core/Log.pm
index a136cc8..e82e324 100644
--- a/lib/Core/Log.pm
+++ b/lib/Core/Log.pm
@@ -44,6 +44,11 @@ The name of the file to monitor.
 
 Regular expression for matching error lines.
 
+=item maxerrs
+
+Maximum number of error lines to include in the error string output. Defaults
+to 5.
+
 =back
 
 =head1 METRICS
@@ -67,6 +72,8 @@ sub handler {
     my $config = $self->{config};
     my $file = $config->{filename};
 
+    $config->{maxerrs} = 5 unless exists($config->{maxerrs});
+
     my @statinfo = stat($file);
 
     if (!exists($self->{file_dev}) ||
@@ -89,8 +96,10 @@ sub handler {
         while(<$log>) {
             chomp;
             if (/$config->{match}/) {
-                $self->{errstring} .= " " if (length($self->{errstring}));
-                $self->{errstring} .= $_;
+                if ($self->{errs} < $config->{maxerrs}) {
+                    $self->{errstring} .= " " if (length($self->{errstring}));
+                    $self->{errstring} .= $_;
+                }
                 $self->{errs}++;
             }
         }
-- 
GitLab