Index: typo3/sysext/scheduler/class.tx_scheduler.php =================================================================== --- typo3/sysext/scheduler/class.tx_scheduler.php (revision 6409) +++ typo3/sysext/scheduler/class.tx_scheduler.php (working copy) @@ -113,14 +113,8 @@ if (($tstamp - $task) < $maxDuration) { $executions[] = $task; } else { - $GLOBALS['BE_USER']->writelog( - 4, - 0, - 0, - 'scheduler', - '[scheduler]: Removing logged execution, assuming that the process is dead. Execution of \'' . $row['classname'] . '\' (UID: ' . $row['uid']. ') was started at '.date('Y-m-d H:i:s', $task), - array() - ); + $logMessage = 'Removing logged execution, assuming that the process is dead. Execution of \'' . $row['classname'] . '\' (UID: ' . $row['uid']. ') was started at '.date('Y-m-d H:i:s', $task); + $this->log($logMessage); } } } @@ -154,33 +148,24 @@ // This should be calculated all the time, even if the execution is skipped // (in case it is skipped, this pushes back execution to the next possible date) $task->save(); + // Set a scheduler object for the task again, + // as it was removed during the save operation + $task->setScheduler(); $result = true; // Task is already running and multiple executions are not allowed if (!$task->areMultipleExecutionsAllowed() && $task->isExecutionRunning()) { // Log multiple execution error - $GLOBALS['BE_USER']->writelog( - 4, - 0, - 0, - 'scheduler', - '[scheduler]: Task is already running and multiple executions are not allowed, skipping! Class: ' . get_class($task) . ', UID: ' . $task->getTaskUid(), - array() - ); + $logMessage = 'Task is already running and multiple executions are not allowed, skipping! Class: ' . get_class($task) . ', UID: ' . $task->getTaskUid(); + $this->log($logMessage); $result = false; // Task isn't running or multiple executions are allowed } else { // Log scheduler invocation - $GLOBALS['BE_USER']->writelog( - 4, - 0, - 0, - 'scheduler', - '[scheduler]: Start execution. Class: ' . get_class($task) . ', UID: ' . $task->getTaskUid(), - array() - ); + $logMessage = 'Start execution. Class: ' . get_class($task) . ', UID: ' . $task->getTaskUid(); + $this->log($logMessage); // Register execution $executionID = $task->markExecution(); @@ -205,14 +190,8 @@ $task->unmarkExecution($executionID, $failure); // Log completion of execution - $GLOBALS['BE_USER']->writelog( - 4, - 0, - 0, - 'scheduler', - '[scheduler]: Task executed. Class: ' . get_class($task). ', UID: ' . $task->getTaskUid(), - array() - ); + $logMessage = 'Task executed. Class: ' . get_class($task). ', UID: ' . $task->getTaskUid(); + $this->log($logMessage); // Now that the result of the task execution has been handled, // throw the exception again, if any @@ -415,6 +394,29 @@ public function isValidTaskObject($task) { return $task instanceof tx_scheduler_Task; } + + /** + * This is a utility method that writes some message to the BE Log + * It could be expanded to write to some other log + * + * @param string The message to write to the log + * @param integer Status (0 = message, 1 = error) + * @param mixed Key for the message + * @return void + */ + public function log($message, $status = 0, $code = 'scheduler') { + // Log only if enabled + if ($this->extConf['enableBELog']) { + $GLOBALS['BE_USER']->writelog( + 4, + 0, + $status, + $code, + '[scheduler]: ' . $message, + array() + ); + } + } } if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/scheduler/class.tx_scheduler.php']) { Index: typo3/sysext/scheduler/class.tx_scheduler_task.php =================================================================== --- typo3/sysext/scheduler/class.tx_scheduler_task.php (revision 6409) +++ typo3/sysext/scheduler/class.tx_scheduler_task.php (working copy) @@ -374,17 +374,11 @@ if ($failure instanceof Exception) { // Log failed execution - $GLOBALS['BE_USER']->writelog( - 4, - 0, - 1, - $failure->getCode(), - '[scheduler]: Task failed to execute successfully. Class: ' + $logMessage = 'Task failed to execute successfully. Class: ' . get_class($this) . ', UID: ' . $this->taskUid . '. ' - . $failure->getMessage(), - array() - ); + . $failure->getMessage(); + $this->scheduler->log($logMessage, 1, $failure->getCode()); $failure = serialize($failure); } else { Index: typo3/sysext/scheduler/ext_conf_template.txt =================================================================== --- typo3/sysext/scheduler/ext_conf_template.txt (revision 6409) +++ typo3/sysext/scheduler/ext_conf_template.txt (working copy) @@ -1,2 +1,5 @@ -# cat=basic//40; type=string; label=Maximum lifetime: Enter the maximum lifetime (in minutes) of a scheduler task. If a task is still running after that time, it will be dropped from the execution list (but not stopped). +# cat=basic//; type=string; label=Maximum lifetime: Enter the maximum lifetime (in minutes) of a scheduler task. If a task is still running after that time, it will be dropped from the execution list (but not stopped). maxLifetime = 1440 + +# cat=basic//; type=boolean; label=Enable logging: When turned on, every start and end of every executed task is logged into TYPO3's BE Log. While this is convenient when setting things up, it may clutter the BE Log in the long run. +enableBELog = 1