Fixed bug #12565: Scheduler: Added option to turn off logging, which could be too...
authorFrancois Suter <francois.suter@typo3.org>
Mon, 16 Nov 2009 21:03:21 +0000 (21:03 +0000)
committerFrancois Suter <francois.suter@typo3.org>
Mon, 16 Nov 2009 21:03:21 +0000 (21:03 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@6432 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/scheduler/class.tx_scheduler.php
typo3/sysext/scheduler/class.tx_scheduler_task.php
typo3/sysext/scheduler/doc/manual.sxw
typo3/sysext/scheduler/ext_conf_template.txt

index bd3fec9..4f6e993 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-11-16  Francois Suter  <francois@typo3.org>
+
+       * Fixed bug #12565: Scheduler: Added option to turn off logging, which could be too verbose
+
 2009-11-16  Oliver Hader  <oliver@typo3.org>
 
        * Fixed bug #12594: "LastLogin"-Field creates PHP error on create (date)
index 2c0d13d..06bf8ab 100755 (executable)
@@ -113,14 +113,8 @@ class tx_scheduler implements t3lib_Singleton {
                                        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 @@ class tx_scheduler implements t3lib_Singleton {
                        // 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 @@ class tx_scheduler implements t3lib_Singleton {
                        $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 @@ class tx_scheduler implements t3lib_Singleton {
        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 96aa76b..630d782 100755 (executable)
@@ -374,17 +374,11 @@ abstract class tx_scheduler_Task {
 
                                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 3668737..c823ed9 100644 (file)
Binary files a/typo3/sysext/scheduler/doc/manual.sxw and b/typo3/sysext/scheduler/doc/manual.sxw differ
index f4e257d..508a551 100644 (file)
@@ -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