[TASK] Streamline usage of Logging 15/57515/2
authorBenni Mack <benni@typo3.org>
Mon, 9 Jul 2018 12:33:42 +0000 (14:33 +0200)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Wed, 11 Jul 2018 09:31:20 +0000 (11:31 +0200)
The Logger can be used with the LoggerAwareInterface+Trait combination
and was fogot for FAL related areas.

The LocalImageProcessor and FileProcessingService did not have any usage
of the logger, thus, they were removed.

Additionally, one should reference against the interfaces, not the implementation
classes directly.

Resolves: #85519
Releases: master
Change-Id: Ie381b1fc9a7007e76ea1c487fa9b1bda4a793bc0
Reviewed-on: https://review.typo3.org/57515
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Reviewed-by: Alexander Schnitzler <typo3@alexanderschnitzler.de>
Tested-by: Alexander Schnitzler <typo3@alexanderschnitzler.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/core/Classes/Resource/Processing/LocalImageProcessor.php
typo3/sysext/core/Classes/Resource/Service/FileProcessingService.php
typo3/sysext/core/Classes/Resource/StorageRepository.php
typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
typo3/sysext/extbase/Classes/SignalSlot/Dispatcher.php
typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php
typo3/sysext/impexp/Classes/Utility/ImportExportUtility.php
typo3/sysext/install/Classes/Updates/BackendLayoutIconUpdateWizard.php
typo3/sysext/install/Classes/Updates/FrontendUserImageUpdateWizard.php

index e9b312d..5c20e50 100644 (file)
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Core\Resource\Processing;
  */
 
 use TYPO3\CMS\Core\Imaging\GraphicalFunctions;
-use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -24,21 +23,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 class LocalImageProcessor implements ProcessorInterface
 {
     /**
-     * @var \TYPO3\CMS\Core\Log\Logger
-     */
-    protected $logger;
-
-    /**
-     * Constructor
-     */
-    public function __construct()
-    {
-        /** @var $logManager LogManager */
-        $logManager = GeneralUtility::makeInstance(LogManager::class);
-        $this->logger = $logManager->getLogger(__CLASS__);
-    }
-
-    /**
      * Returns TRUE if this processor can process the given task.
      *
      * @param TaskInterface $task
index 2606b27..c9a8ebe 100644 (file)
@@ -14,7 +14,6 @@ namespace TYPO3\CMS\Core\Resource\Service;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Resource;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Object\ObjectManager;
@@ -40,11 +39,6 @@ class FileProcessingService
      */
     protected $signalSlotDispatcher;
 
-    /**
-     * @var \TYPO3\CMS\Core\Log\Logger
-     */
-    protected $logger;
-
     const SIGNAL_PreFileProcess = 'preFileProcess';
     const SIGNAL_PostFileProcess = 'postFileProcess';
 
@@ -58,10 +52,6 @@ class FileProcessingService
     {
         $this->storage = $storage;
         $this->driver = $driver;
-
-        /** @var $logManager LogManager */
-        $logManager = GeneralUtility::makeInstance(LogManager::class);
-        $this->logger = $logManager->getLogger(__CLASS__);
     }
 
     /**
index f72be68..403dae6 100644 (file)
@@ -14,18 +14,21 @@ namespace TYPO3\CMS\Core\Resource;
  * The TYPO3 project - inspiring people to share!
  */
 
+use Psr\Log\LoggerAwareInterface;
+use Psr\Log\LoggerAwareTrait;
 use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
 use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer;
-use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Repository for accessing the file mounts
  */
-class StorageRepository extends AbstractRepository
+class StorageRepository extends AbstractRepository implements LoggerAwareInterface
 {
+    use LoggerAwareTrait;
+
     /**
      * @var array|null
      */
@@ -52,20 +55,6 @@ class StorageRepository extends AbstractRepository
     protected $driverField = 'driver';
 
     /**
-     * @var \TYPO3\CMS\Core\Log\Logger
-     */
-    protected $logger;
-
-    public function __construct()
-    {
-        parent::__construct();
-
-        /** @var $logManager LogManager */
-        $logManager = GeneralUtility::makeInstance(LogManager::class);
-        $this->logger = $logManager->getLogger(__CLASS__);
-    }
-
-    /**
      * @param int $uid
      *
      * @return ResourceStorage|null
index c088c75..e2894e8 100644 (file)
@@ -20,6 +20,7 @@ use TYPO3\CMS\Backend\Routing\Router;
 use TYPO3\CMS\Core\Category\CategoryRegistry;
 use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Imaging\IconRegistry;
+use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Migrations\TcaMigration;
 use TYPO3\CMS\Core\Package\PackageManager;
 use TYPO3\CMS\Core\Preparations\TcaPreparation;
@@ -1942,12 +1943,12 @@ tt_content.' . $key . $suffix . ' {
         // Update the category registry
         $result = CategoryRegistry::getInstance()->add($extensionKey, $tableName, $fieldName, $options, $override);
         if ($result === false) {
-            $message = CategoryRegistry::class . ': no category registered for table "%s". Key was already registered.';
-            /** @var $logger \TYPO3\CMS\Core\Log\Logger */
-            $logger = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
-            $logger->warning(
-                sprintf($message, $tableName)
-            );
+            GeneralUtility::makeInstance(LogManager::class)
+                ->getLogger(__CLASS__)
+                ->warning(sprintf(
+                    CategoryRegistry::class . ': no category registered for table "%s". Key was already registered.',
+                    $tableName
+                ));
         }
     }
 }
index 3fd3375..32399c1 100644 (file)
@@ -14,7 +14,7 @@ namespace TYPO3\CMS\Extbase\SignalSlot;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Core\Log\Logger;
+use Psr\Log\LoggerInterface;
 use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Object\ObjectManager;
@@ -48,7 +48,7 @@ class Dispatcher implements \TYPO3\CMS\Core\SingletonInterface
     protected $slots = [];
 
     /**
-     * @var Logger
+     * @var LoggerInterface
      */
     protected $logger;
 
index 7d274e8..6e1264e 100644 (file)
@@ -605,7 +605,6 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface
                 $this->registry->set('extensionDataImport', $extensionSiteRelPath . 'Initialisation/dataImported', 1);
                 $this->emitAfterExtensionT3DImportSignal($importFileToUse, $importResult);
             } catch (\ErrorException $e) {
-                /** @var \TYPO3\CMS\Core\Log\Logger $logger */
                 $logger = $this->objectManager->get(\TYPO3\CMS\Core\Log\LogManager::class)->getLogger(__CLASS__);
                 $logger->log(\TYPO3\CMS\Core\Log\LogLevel::WARNING, $e->getMessage());
             }
index 43cdea2..e455308 100644 (file)
@@ -62,7 +62,6 @@ class ImportExportUtility
         // Check for errors during the import process:
         $errors = $import->printErrorLog();
         if ($errors !== '') {
-            /** @var \TYPO3\CMS\Core\Log\Logger $logger */
             $logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
             $logger->warning($errors);
 
index 5cf9a0f..85c25ba 100644 (file)
@@ -15,11 +15,11 @@ namespace TYPO3\CMS\Install\Updates;
  * The TYPO3 project - inspiring people to share!
  */
 use Doctrine\DBAL\DBALException;
+use Psr\Log\LoggerAwareInterface;
+use Psr\Log\LoggerAwareTrait;
 use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
-use TYPO3\CMS\Core\Log\Logger;
-use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\ResourceStorage;
 use TYPO3\CMS\Core\Resource\StorageRepository;
@@ -30,8 +30,10 @@ use TYPO3\CMS\Core\Utility\PathUtility;
  * Upgrade wizard which goes through all files referenced in backend_layout.icon
  * and creates sys_file records as well as sys_file_reference records for each hit.
  */
-class BackendLayoutIconUpdateWizard extends AbstractUpdate
+class BackendLayoutIconUpdateWizard extends AbstractUpdate implements LoggerAwareInterface
 {
+    use LoggerAwareTrait;
+
     /**
      * @var string
      */
@@ -43,11 +45,6 @@ class BackendLayoutIconUpdateWizard extends AbstractUpdate
     protected $storage;
 
     /**
-     * @var Logger
-     */
-    protected $logger;
-
-    /**
      * Table to migrate records from
      *
      * @var string
@@ -77,14 +74,6 @@ class BackendLayoutIconUpdateWizard extends AbstractUpdate
     protected $targetPath = '_migrated/backend_layouts/';
 
     /**
-     * Constructor
-     */
-    public function __construct()
-    {
-        $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
-    }
-
-    /**
      * Checks if an update is needed
      *
      * @param string &$description The description for the update
index 2b2ff81..fc96f35 100644 (file)
@@ -14,12 +14,12 @@ namespace TYPO3\CMS\Install\Updates;
  * The TYPO3 project - inspiring people to share!
  */
 use Doctrine\DBAL\DBALException;
+use Psr\Log\LoggerAwareInterface;
+use Psr\Log\LoggerAwareTrait;
 use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
-use TYPO3\CMS\Core\Log\Logger;
-use TYPO3\CMS\Core\Log\LogManager;
 use TYPO3\CMS\Core\Registry;
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\ResourceStorage;
@@ -31,8 +31,9 @@ use TYPO3\CMS\Core\Utility\PathUtility;
  * Upgrade wizard which goes through all files referenced in fe_users::image
  * and creates sys_file records as well as sys_file_reference records for each hit.
  */
-class FrontendUserImageUpdateWizard extends AbstractUpdate
+class FrontendUserImageUpdateWizard extends AbstractUpdate implements LoggerAwareInterface
 {
+    use LoggerAwareTrait;
 
     /**
      * Number of records fetched per database query
@@ -51,11 +52,6 @@ class FrontendUserImageUpdateWizard extends AbstractUpdate
     protected $storage;
 
     /**
-     * @var Logger
-     */
-    protected $logger;
-
-    /**
      * Table to migrate records from
      *
      * @var string
@@ -100,14 +96,6 @@ class FrontendUserImageUpdateWizard extends AbstractUpdate
     protected $recordOffset = [];
 
     /**
-     * Constructor
-     */
-    public function __construct()
-    {
-        $this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
-    }
-
-    /**
      * Initialize the storage repository.
      */
     public function init()