Added Logger object for constructing a logging instance for an application
This commit is contained in:
parent
e35eb46873
commit
3bf6b70526
2 changed files with 100 additions and 1 deletions
|
@ -25,10 +25,16 @@
|
||||||
* @param Application $application The options for the application
|
* @param Application $application The options for the application
|
||||||
* @return bool
|
* @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(self::isRegistered($application->getApplicationName()))
|
||||||
{
|
{
|
||||||
|
if($overwrite)
|
||||||
|
{
|
||||||
|
self::$applications[$application->getApplicationName()] = $application;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
93
src/LogLib/Logger.php
Normal file
93
src/LogLib/Logger.php
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace LogLib;
|
||||||
|
|
||||||
|
use LogLib\Exceptions\LoggingException;
|
||||||
|
use LogLib\Objects\Application;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class Logger extends Application
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function __construct(string $applicationName)
|
||||||
|
{
|
||||||
|
parent::__construct($applicationName);
|
||||||
|
Log::register($this, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logs an informational message.
|
||||||
|
*
|
||||||
|
* @param string $message The message to log.
|
||||||
|
* @return void
|
||||||
|
* @throws LoggingException
|
||||||
|
*/
|
||||||
|
public function info(string $message): void
|
||||||
|
{
|
||||||
|
Log::info($this->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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue