Remove redundant instatation of loggers in static classes

Use the one from Helper class
This commit is contained in:
Beatrycze Volk 2021-10-11 10:46:54 +02:00
parent 94ae10c72f
commit 5ccee98ef2
4 changed files with 12 additions and 28 deletions

View File

@ -736,8 +736,6 @@ abstract class Document
*/
public static function getTitle($uid, $recursive = false)
{
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
$title = '';
// Sanitize input.
$uid = max(intval($uid), 0);
@ -772,10 +770,10 @@ abstract class Document
$title = self::getTitle($partof, true);
}
} else {
$logger->warning('No document with UID ' . $uid . ' found or document not accessible');
Helper::log('No document with UID ' . $uid . ' found or document not accessible', LOG_SEVERITY_WARNING);
}
} else {
$logger->error('Invalid UID ' . $uid . ' for document');
Helper::log('Invalid UID ' . $uid . ' for document', LOG_SEVERITY_ERROR);
}
return $title;
}

View File

@ -230,10 +230,9 @@ class Helper
*
* @return void
*/
//TODO: find better way to handle logger in static class
public static function log($message, $severity = 0)
{
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(get_called_class());
switch ($severity) {
case 0:

View File

@ -14,7 +14,6 @@ namespace Kitodo\Dlf\Common;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
@ -93,8 +92,6 @@ class Indexer
*/
public static function add(Document &$doc, $core = 0)
{
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
if (in_array($doc->uid, self::$processedDocs)) {
return true;
} elseif (self::solrConnect($core, $doc->pid)) {
@ -105,7 +102,7 @@ class Indexer
if ($parent->ready) {
$success = self::add($parent, $core);
} else {
$logger->error('Could not load parent document with UID ' . $doc->parentId);
Helper::log('Could not load parent document with UID ' . $doc->parentId, LOG_SEVERITY_ERROR);
return false;
}
}
@ -186,7 +183,7 @@ class Indexer
'core.template.flashMessages'
);
}
$logger->error('Apache Solr threw exception: "' . $e->getMessage() . '"');
Helper::log('Apache Solr threw exception: "' . $e->getMessage() . '"', LOG_SEVERITY_ERROR);
return false;
}
} else {
@ -199,7 +196,7 @@ class Indexer
'core.template.flashMessages'
);
}
$logger->error('Could not connect to Apache Solr server');
Helper::log('Could not connect to Apache Solr server', LOG_SEVERITY_ERROR);
return false;
}
}
@ -216,12 +213,10 @@ class Indexer
*/
public static function getIndexFieldName($index_name, $pid = 0)
{
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
// Sanitize input.
$pid = max(intval($pid), 0);
if (!$pid) {
$logger->error('Invalid PID ' . $pid . ' for metadata configuration');
Helper::log('Invalid PID ' . $pid . ' for metadata configuration', LOG_SEVERITY_ERROR);
return '';
}
// Load metadata configuration.
@ -316,8 +311,6 @@ class Indexer
*/
protected static function processLogical(Document &$doc, array $logicalUnit)
{
$logger = GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
$success = true;
// Get metadata for logical unit.
$metadata = $doc->metadataArray[$logicalUnit['id']];
@ -332,7 +325,7 @@ class Indexer
// Replace owner UID with index_name.
if (
!empty($metadata['owner'][0])
&& \TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($metadata['owner'][0])
&& MathUtility::canBeInterpretedAsInteger($metadata['owner'][0])
) {
$metadata['owner'][0] = Helper::getIndexNameFromUid($metadata['owner'][0], 'tx_dlf_libraries', $doc->cPid);
}
@ -417,7 +410,7 @@ class Indexer
'core.template.flashMessages'
);
}
$logger->error('Apache Solr threw exception: "' . $e->getMessage() . '"');
Helper::log('Apache Solr threw exception: "' . $e->getMessage() . '"', LOG_SEVERITY_ERROR);
return false;
}
}
@ -448,8 +441,6 @@ class Indexer
*/
protected static function processPhysical(Document &$doc, $page, array $physicalUnit)
{
$logger = GeneralUtility::makeInstance('TYPO3\CMS\Core\Log\LogManager')->getLogger(__CLASS__);
if ($doc->hasFulltext && $fullText = $doc->getFullText($physicalUnit['id'])) {
// Read extension configuration.
$extConf = GeneralUtility::makeInstance(ExtensionConfiguration::class)->get(self::$extKey);
@ -516,7 +507,7 @@ class Indexer
'core.template.flashMessages'
);
}
$logger->error('Apache Solr threw exception: "' . $e->getMessage() . '"');
Helper::log('Apache Solr threw exception: "' . $e->getMessage() . '"', LOG_SEVERITY_ERROR);
return false;
}
}

View File

@ -132,8 +132,6 @@ class Solr implements LoggerAwareInterface
*/
public static function createCore($core = '')
{
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
// Get next available core name if none given.
if (empty($core)) {
$core = 'dlfCore' . self::getNextCoreNumber();
@ -165,7 +163,7 @@ class Solr implements LoggerAwareInterface
// Nothing to do here.
}
} else {
$logger->error('Apache Solr not available');
Helper::log('Apache Solr not available', LOG_SEVERITY_ERROR);
}
}
return '';
@ -300,8 +298,6 @@ class Solr implements LoggerAwareInterface
*/
public static function getInstance($core = null)
{
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
// Get core name if UID is given.
if (MathUtility::canBeInterpretedAsInteger($core)) {
$core = Helper::getIndexNameFromUid($core, 'tx_dlf_solrcores');
@ -311,7 +307,7 @@ class Solr implements LoggerAwareInterface
empty($core)
&& $core !== null
) {
$logger->error('Invalid core UID or name given for Apache Solr');
Helper::log('Invalid core UID or name given for Apache Solr', LOG_SEVERITY_ERROR);
}
if (!empty($core)) {
// Check if there is an instance in the registry already.