Skip to content

Commit

Permalink
[FEATURE] Toggle exception logging in main extension configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Aug 4, 2024
1 parent afc99d9 commit ac8057b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Classes/Controller/FrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use In2code\Lux\Exception\EmailValidationException;
use In2code\Lux\Exception\FakeException;
use In2code\Lux\Utility\BackendUtility;
use In2code\Lux\Utility\ConfigurationUtility;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -456,11 +457,13 @@ protected function getError(Throwable $exception): array
{
$this->eventDispatcher->dispatch(new AfterTrackingEvent(new Visitor(), 'error', ['error' => $exception]));
if (BackendUtility::isBackendAuthentication() === false) {
// Log error to var/log/typo3_[hash].log
$this->logger->warning('Error in FrontendController happened', [
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
]);
if (ConfigurationUtility::isExceptionLoggingActivated()) {
// Log error to var/log/typo3_[hash].log
$this->logger->warning('Error in FrontendController happened', [
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
]);
}
$exception = new FakeException('Error happened', 1680200937);
}
return [
Expand Down
11 changes: 11 additions & 0 deletions Classes/Utility/ConfigurationUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,17 @@ public static function isAnalysisModuleDisabled(): bool
return $extensionConfig['disableAnalysisModule'] === '1';
}

/**
* @return bool
* @throws ExtensionConfigurationExtensionNotConfiguredException
* @throws ExtensionConfigurationPathDoesNotExistException
*/
public static function isExceptionLoggingActivated(): bool
{
$extensionConfig = self::getExtensionConfiguration();
return $extensionConfig['enbaleExceptionLogging'] === '1';
}

/**
* @return bool
* @throws ExtensionConfigurationExtensionNotConfiguredException
Expand Down
3 changes: 3 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ showRenderTimes = 0

# cat=advanced/enable/270; type=boolean; label= Use cache layer: Performance boost for backend views. Cache layer could be used for both dashboard views and quick analyse in page overview view. Lifetime is per default 24h and caches can be warmed up via scheduler task.
useCacheLayer = 1

# cat=advanced/enable/280; type=boolean; label= Enable exception logging: If the user is not logged in into backend and an exception happens, those exceptions can be logged as warning in var/log/typo3_[hash].log
enbaleExceptionLogging = 1

0 comments on commit ac8057b

Please sign in to comment.