Skip to content

Commit

Permalink
Merge pull request #16 from b13/task/logging
Browse files Browse the repository at this point in the history
[TASK] Logger Registration
  • Loading branch information
bmack authored May 21, 2024
2 parents 5d0cedf + 7d79e8c commit 339b050
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use TYPO3\CMS\Core\Information\Typo3Version;
use TYPO3\CMS\Core\Log\LogLevel;
use TYPO3\CMS\Core\Log\Writer\FileWriter;
use TYPO3\CMS\Core\Log\Writer\NullWriter;
use TYPO3\CMS\Core\Utility\ArrayUtility;

/**
* Class to use in your configuration files of a TYPO3 project.
Expand Down Expand Up @@ -330,13 +332,39 @@ public function autoconfigureSolrLogging(string $fileName = 'solr.log', string $
} else {
$logLevel = $this->context->isProduction() ? LogLevel::ERROR : LogLevel::DEBUG;
}
$GLOBALS['TYPO3_CONF_VARS']['LOG']['ApacheSolrForTypo3']['Solr']['writerConfiguration'] = [
$logLevel => [
FileWriter::class => [
'logFile' => $this->varPath . '/log/' . $fileName,
return $this->addFileLogger('ApacheSolrForTypo3\\Solr', $fileName, $logLevel);
}

public function addFileLogger(string $namespace, string $fileName = null, string $logLevel = null): self
{
$fileName = $fileName ?? strtolower(str_replace('\\', '_', $namespace)) . '.log';
if ($logLevel === null) {
$logLevel = $this->context->isProduction() ? LogLevel::ERROR : LogLevel::DEBUG;
}
$logFile = $this->varPath . '/log/' . $fileName;
$value = [
'writerConfiguration' => [
$logLevel => [
FileWriter::class => [
'logFile' => $logFile,
],
],
],
];
$GLOBALS['TYPO3_CONF_VARS']['LOG'] = ArrayUtility::setValueByPath($GLOBALS['TYPO3_CONF_VARS']['LOG'], $namespace, $value, '\\');
return $this;
}

public function setNullLogger(string $namespace, string $logLevel = LogLevel::DEBUG): self
{
$value = [
'writerConfiguration' => [
$logLevel => [
NullWriter::class => [],
],
],
];
$GLOBALS['TYPO3_CONF_VARS']['LOG'] = ArrayUtility::setValueByPath($GLOBALS['TYPO3_CONF_VARS']['LOG'], $namespace, $value, '\\');
return $this;
}

Expand Down

0 comments on commit 339b050

Please sign in to comment.