From 3bf6b70526eaabb6d72a473cc4e2c781d0f1a631 Mon Sep 17 00:00:00 2001 From: netkas Date: Mon, 28 Oct 2024 19:36:26 -0400 Subject: [PATCH] Added Logger object for constructing a logging instance for an application --- src/LogLib/Log.php | 8 +++- src/LogLib/Logger.php | 93 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 src/LogLib/Logger.php diff --git a/src/LogLib/Log.php b/src/LogLib/Log.php index fb78a23..17cd913 100644 --- a/src/LogLib/Log.php +++ b/src/LogLib/Log.php @@ -25,10 +25,16 @@ * @param Application $application The options for the application * @return bool */ - public static function register(Application $application): bool + public static function register(Application $application, bool $overwrite=false): bool { if(self::isRegistered($application->getApplicationName())) { + if($overwrite) + { + self::$applications[$application->getApplicationName()] = $application; + return true; + } + return false; } diff --git a/src/LogLib/Logger.php b/src/LogLib/Logger.php new file mode 100644 index 0000000..5af777e --- /dev/null +++ b/src/LogLib/Logger.php @@ -0,0 +1,93 @@ +getApplicationName(), $message); + } + + /** + * Logs a verbose message with the application name. + * + * @param string $message The message to be logged. + * @return void + * @throws LoggingException + */ + public function verbose(string $message): void + { + Log::verbose($this->getApplicationName(), $message); + } + + /** + * Logs a debug message. + * + * @param string $message The debug message to log. + * @return void + * @throws LoggingException + */ + public function debug(string $message): void + { + Log::debug($this->getApplicationName(), $message); + } + + /** + * Logs a warning message with the application name. + * + * @param string $message The warning message to log. + * @return void + * @throws LoggingException + */ + public function warning(string $message): void + { + Log::warning($this->getApplicationName(), $message); + } + + /** + * Logs an error message with an optional throwable instance. + * + * @param string $message The error message to be logged. + * @param Throwable|null $throwable An optional throwable instance to be logged along with the error message. + * @return void + * @throws LoggingException + */ + public function error(string $message, ?Throwable $throwable=null): void + { + Log::error($this->getApplicationName(), $message, $throwable); + } + + /** + * Logs a fatal error message along with an optional throwable. + * + * @param string $message The fatal error message to log. + * @param Throwable|null $throwable Optional throwable associated with the fatal error. + * @return void + * @throws LoggingException + */ + public function fatal(string $message, ?Throwable $throwable=null): void + { + Log::fatal($this->getApplicationName(), $message, $throwable); + } +} \ No newline at end of file