Skip to content

Commit

Permalink
Silence DebugWriter for PageIndexerRequest
Browse files Browse the repository at this point in the history
If debug logging is activated the DebugWriter
does append debug messages to the output. This
fails when running PageIndexerRequest as it
does return a json that must not be appended
with debug message output.

Fixes: #3030
  • Loading branch information
sascha-egerer authored and dkd-kaehm committed Jul 16, 2022
1 parent 506b540 commit 56203df
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Classes/System/Logging/DebugWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@

namespace ApacheSolrForTypo3\Solr\System\Logging;

use ApacheSolrForTypo3\Solr\IndexQueue\PageIndexerRequest;
use ApacheSolrForTypo3\Solr\Util;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Core\Http\Request;
use TYPO3\CMS\Core\Utility\DebugUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;

/**
* The DebugWriter is used to write the devLog messages to the output of the page, or to the TYPO3 console in the
* backend to provide a simple and lightweigt debugging possibility.
* backend to provide a simple and lightweight debugging possibility.
*
* @author Timo Hund <timo.hund@dkd.de>
*/
Expand All @@ -50,6 +52,11 @@ public function write($level, $message, $data = [])
return;
}

$isPageIndexingRequest = $this->getIsPageIndexingRequest();
if ($isPageIndexingRequest) {
return;
}

$this->writeDebugMessage($level, $message, $data);
}

Expand All @@ -71,6 +78,14 @@ protected function getIsDebugOutputEnabled()
return Util::getSolrConfiguration()->getLoggingDebugOutput();
}

protected function getIsPageIndexingRequest(): bool
{
if (!($GLOBALS['TYPO3_REQUEST'] ?? null) instanceof Request) {
return false;
}
return $GLOBALS['TYPO3_REQUEST']->hasHeader(PageIndexerRequest::SOLR_INDEX_HEADER);
}

/**
* @param int|string $level Log level. Value according to \TYPO3\CMS\Core\Log\LogLevel. Alternatively accepts a string.
* @param string $message Log message.
Expand All @@ -79,7 +94,7 @@ protected function getIsDebugOutputEnabled()
protected function writeDebugMessage($level, $message, $data)
{
$parameters = ['extKey' => 'solr', 'msg' => $message, 'level' => $level, 'data' => $data];
$message = isset($parameters['msg']) ? $parameters['msg'] : '';
$message = $parameters['msg'] ?? '';
if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) {
DebugUtility::debug($parameters, $parameters['extKey'], 'DevLog ext:solr: ' . $message);
} else {
Expand Down

0 comments on commit 56203df

Please sign in to comment.