[icinga-checkins] icinga.org: icingaweb2-module-director/master: CoreApi: shorten startup log

git at icinga.org git at icinga.org
Tue Jul 26 13:14:29 CEST 2016


Module: icingaweb2-module-director
Branch: master
Commit: f6c1a9f0f7dcaf4a80fc7b9daf853b18c4ae40ea
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=f6c1a9f0f7dcaf4a80fc7b9daf853b18c4ae40ea

Author: Thomas Gelf <thomas at gelf.net>
Date:   Tue Jul 26 13:08:37 2016 +0200

CoreApi: shorten startup log

Everything more than 60k is absolutely insane

fixes #12231

---

 library/Director/Core/CoreApi.php |   27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/library/Director/Core/CoreApi.php b/library/Director/Core/CoreApi.php
index 98bfeb3..2a3d7df 100644
--- a/library/Director/Core/CoreApi.php
+++ b/library/Director/Core/CoreApi.php
@@ -490,7 +490,9 @@ constants
                 } else {
                     $deployment->startup_succeeded = 'n';
                 }
-                $deployment->startup_log = $this->getStagedFile($stage, 'startup.log');
+                $deployment->startup_log = $this->shortenStartupLog(
+                    $this->getStagedFile($stage, 'startup.log')
+                );
             }
             $collected = true;
 
@@ -629,4 +631,27 @@ constants
         $deployment->store($db);
         return $deployment->dump_succeeded === 'y';
     }
+
+    protected function shortenStartupLog($log)
+    {
+        $logLen = strlen($log);
+        if ($logLen < 1024 * 60) {
+            return $log;
+        }
+
+        $part = substr($log, 0, 1024 * 20);
+        $parts = explode("\n", $part);
+        array_pop($parts);
+        $begin = implode("\n", $parts) . "\n\n";
+
+        $part = substr($log, -1024 * 20);
+        $parts = explode("\n", $part);
+        array_shift($parts);
+        $end = "\n\n" . implode("\n", $parts);
+
+        return $begin . sprintf(
+            '[..] %d bytes removed by Director [..]',
+            $logLen - (strlen($begin) + strlen($end))
+        ) . $end;
+    }
 }



More information about the icinga-checkins mailing list