Refactor exception handling in FileLogging

This commit is contained in:
netkas 2024-10-30 00:14:33 -04:00
parent 9fdedc5dea
commit 9435841987
2 changed files with 9 additions and 12 deletions

View file

@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
This update introduces minor improvements This update introduces minor improvements
### Changed
- Refactored exception handling in FileLogging where it will always attempt to print the exception no matter
the log level for as long as the log level isn't silent
## [2.0.1] - 2024-10-29 ## [2.0.1] - 2024-10-29

View file

@ -29,32 +29,25 @@ class FileLogging implements LogHandlerInterface
if(Validate::checkLevelType(LogLevel::DEBUG, $application->getConsoleLoggingLevel())) if(Validate::checkLevelType(LogLevel::DEBUG, $application->getConsoleLoggingLevel()))
{ {
$backtrace_output = Utilities::getTraceString($event, false); $backtrace_output = Utilities::getTraceString($event, false);
$output = sprintf("[%s] [%s] [%s] %s %s" . PHP_EOL, $output = sprintf("[%s] [%s] [%s] %s %s" . PHP_EOL,
self::getTimestamp(), $application->getApplicationName(), $event->getLevel()->name, $backtrace_output, $event->getMessage() self::getTimestamp(), $application->getApplicationName(), $event->getLevel()->name, $backtrace_output, $event->getMessage()
); );
if($event->getException() !== null)
{
$output .= self::outException($event->getException());
}
} }
else if(Validate::checkLevelType(LogLevel::VERBOSE, $application->getConsoleLoggingLevel())) else if(Validate::checkLevelType(LogLevel::VERBOSE, $application->getConsoleLoggingLevel()))
{ {
$backtrace_output = Utilities::getTraceString($event, false); $backtrace_output = Utilities::getTraceString($event, false);
$output = sprintf("[%s] [%s] [%s] %s %s" . PHP_EOL, self::getTimestamp(), $application->getApplicationName(), $event->getLevel()->name, $backtrace_output, $event->getMessage()); $output = sprintf("[%s] [%s] [%s] %s %s" . PHP_EOL, self::getTimestamp(), $application->getApplicationName(), $event->getLevel()->name, $backtrace_output, $event->getMessage());
if($event->getException() !== null)
{
$output .= self::outException($event->getException());
}
} }
else else
{ {
$output = sprintf("[%s] [%s] [%s] %s" . PHP_EOL, self::getTimestamp(), $application->getApplicationName(), $event->getLevel()->name, $event->getMessage()); $output = sprintf("[%s] [%s] [%s] %s" . PHP_EOL, self::getTimestamp(), $application->getApplicationName(), $event->getLevel()->name, $event->getMessage());
} }
if($event->getException() !== null)
{
$output .= self::outException($event->getException());
}
self::getLogger($application)->append($output); self::getLogger($application)->append($output);
} }