From 994a9de00b76430976bafe79234393be9ed01b52 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sat, 7 Dec 2019 13:51:46 +0100 Subject: [apis/cron] Simple logging function for debugging --- apis/cron.inc.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/apis/cron.inc.php b/apis/cron.inc.php index 75d7f132..d00c179c 100644 --- a/apis/cron.inc.php +++ b/apis/cron.inc.php @@ -62,9 +62,25 @@ function getJobStatus($id) } // Hooks by other modules -function handleModule($file) +/** + * @param Hook $hook + */ +function handleModule($hook) { - include_once $file; + global $cron_log_text; + $cron_log_text = ''; + include_once $hook->file; + if (!empty($cron_log_text)) { + EventLog::info('CronJob ' . $hook->moduleId . ' finished.', $cron_log_text); + } +} + +$cron_log_text = ''; +function cron_log($text) +{ + // XXX: Enable this code for debugging -- make this configurable some day + //global $cron_log_text; + //$cron_log_text .= $text . "\n"; } $blocked = Property::getList(CRON_KEY_BLOCKED); @@ -93,7 +109,7 @@ foreach (Hook::load('cron') as $hook) { $value = $hook->moduleId . '|' . time(); Property::addToList(CRON_KEY_STATUS, $value, 30); try { - handleModule($hook->file); + handleModule($hook); } catch (Exception $e) { // Logging EventLog::failure('Cronjob for module ' . $hook->moduleId . ' has crashed. Check the php or web server error log.', $e->getMessage()); -- cgit v1.2.3-55-g7522