From de75ba60a58e87778551a7a7258352a4cc30fddc Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 25 Mar 2019 22:07:12 +0100 Subject: api/taskman: Improve logging --- api.php | 25 +++++++++++++++++-------- apis/init.inc.php | 4 ++++ inc/taskmanager.inc.php | 1 + 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/api.php b/api.php index df54d7f5..9e43a42a 100644 --- a/api.php +++ b/api.php @@ -57,14 +57,23 @@ if (Module::isAvailable($module)) { if (!file_exists($module)) { Util::traceError('Invalid module, or module without API: ' . $module); } -Header('Expires: Wed, 29 Mar 2007 09:56:28 GMT'); -Header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); -Header("Cache-Control: post-check=0, pre-check=0", false); -Header("Pragma: no-cache"); - -Header('Content-Type: text/plain; charset=utf-8'); - -ob_start('ob_gzhandler'); +if (php_sapi_name() === 'cli') { + register_shutdown_function(function() { + if (class_exists('Message', false)) { + $text = Message::asString(); + if (!empty($text)) { + error_log("The following error messages were generated:\n" . $text); + } + } + }); +} else { + Header('Expires: Wed, 29 Mar 2007 09:56:28 GMT'); + Header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); + Header("Cache-Control: post-check=0, pre-check=0", false); + Header("Pragma: no-cache"); + Header('Content-Type: text/plain; charset=utf-8'); + ob_start('ob_gzhandler'); +} // Load module - it will execute pre-processing, or act upon request parameters require_once($module); diff --git a/apis/init.inc.php b/apis/init.inc.php index e0dcf707..8641fecd 100644 --- a/apis/init.inc.php +++ b/apis/init.inc.php @@ -10,6 +10,10 @@ if (($report = Request::get('crashreport', false, 'string')) !== false) { $details = file_get_contents($report); EventLog::failure('Problems during bootup hook', $details); exit(0); +} elseif (($report = Request::get('logreport', false, 'string')) !== false) { + $details = file_get_contents($report); + EventLog::info('Messages during bootup hook', $details); + exit(0); } Event::systemBooted(); diff --git a/inc/taskmanager.inc.php b/inc/taskmanager.inc.php index dab950ed..8fe70d00 100644 --- a/inc/taskmanager.inc.php +++ b/inc/taskmanager.inc.php @@ -247,6 +247,7 @@ class Taskmanager if (++$tries > 10) return false; } + error_log('Reading taskmanager reply failed, socket error ' . socket_last_error()); return false; } -- cgit v1.2.3-55-g7522