[TASK] Log exception when metadata extraction fails 65/51965/16
authorThomas Hohn <thomas@hohn.dk>
Mon, 6 Mar 2017 19:13:39 +0000 (20:13 +0100)
committerMarkus Klein <markus.klein@typo3.org>
Fri, 24 Mar 2017 11:02:09 +0000 (12:02 +0100)
When the FAL metadata extraction task fails with an exception
this exception will now be logged via logException(), which is
added as a new method to AbstractTask. This method logs via
GeneralUtility::sysLog and the Logging API.

Resolves: #66217
Releases: master
Change-Id: If7d56148d9ee3ec3ea143bc422eeff4f2f4b8c03
Reviewed-on: https://review.typo3.org/51965
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Sommer <markussom@posteo.de>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/scheduler/Classes/Task/AbstractTask.php
typo3/sysext/scheduler/Classes/Task/FileStorageExtractionTask.php

index db3a88c..8cf8c5e 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Scheduler\Task;
 
 use TYPO3\CMS\Core\Database\Connection;
 use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -601,4 +602,26 @@ abstract class AbstractTask
         }
         return self::TYPE_SINGLE;
     }
+
+    /**
+     * Log exception via GeneralUtility::sysLog
+     *
+     * @param \Exception $e
+     */
+    protected function logException(\Exception $e)
+    {
+        GeneralUtility::sysLog($e->getMessage(), 'scheduler', GeneralUtility::SYSLOG_SEVERITY_ERROR);
+        $this->getLogger()->error('A Task Exception was captured: ' . $e->getMessage() . ' (' . $e->getCode() . ')', ['exception' => $e]);
+    }
+
+    /**
+     * Instantiates a logger
+     *
+     * @return \TYPO3\CMS\Core\Log\Logger
+     */
+    protected function getLogger()
+    {
+        $logManager = GeneralUtility::makeInstance(LogManager::class);
+        return $logManager->getLogger(get_class($this));
+    }
 }
index 394015f..a089736 100644 (file)
@@ -50,6 +50,7 @@ class FileStorageExtractionTask extends \TYPO3\CMS\Scheduler\Task\AbstractTask
                 $success = true;
             } catch (\Exception $e) {
                 $success = false;
+                $this->logException($e);
             }
             $storage->setEvaluatePermissions(true);
         }