From 94358419872970024f359a14bdead4b02b6108fc Mon Sep 17 00:00:00 2001 From: netkas Date: Wed, 30 Oct 2024 00:14:33 -0400 Subject: [PATCH] Refactor exception handling in FileLogging --- CHANGELOG.md | 4 ++++ src/LogLib/Handlers/FileLogging.php | 17 +++++------------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ca5529..4fb8dd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 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 diff --git a/src/LogLib/Handlers/FileLogging.php b/src/LogLib/Handlers/FileLogging.php index 95eaf27..0333dfa 100644 --- a/src/LogLib/Handlers/FileLogging.php +++ b/src/LogLib/Handlers/FileLogging.php @@ -29,32 +29,25 @@ class FileLogging implements LogHandlerInterface if(Validate::checkLevelType(LogLevel::DEBUG, $application->getConsoleLoggingLevel())) { $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() ); - - if($event->getException() !== null) - { - $output .= self::outException($event->getException()); - } } else if(Validate::checkLevelType(LogLevel::VERBOSE, $application->getConsoleLoggingLevel())) { $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()); - - if($event->getException() !== null) - { - $output .= self::outException($event->getException()); - } } else { $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); }