From f47200d70ae5bb0209d09a3d8556e6260d29d63c Mon Sep 17 00:00:00 2001 From: 8ctopus Date: Thu, 28 Jul 2022 14:39:57 +0500 Subject: [PATCH] Add get log destination Add check log empty --- src/Logger/AbstractLogger.php | 23 +++++++++++++++++++++-- src/Logger/ErrorLog.php | 11 ++++++++++- src/Logger/File.php | 2 -- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/Logger/AbstractLogger.php b/src/Logger/AbstractLogger.php index 40a25dc..a2f3832 100644 --- a/src/Logger/AbstractLogger.php +++ b/src/Logger/AbstractLogger.php @@ -74,6 +74,12 @@ abstract class AbstractLogger extends PsrAbstractLogger */ protected $options = array(); + /** + * Whether or not log is empty. + * @var bool + */ + protected $empty = true; + /** * Gets the named level code. * @@ -111,6 +117,10 @@ public function log($level, Stringable|string $message, array $context = array() */ public function process(LogEntry $log) { + if ($this->empty) { + $this->empty = false; + } + if ($this->deferred) { $this->deferred_logs[] = $log; } else { @@ -276,7 +286,7 @@ public function setLogFormatter(LogFormatter $formatter) * @return LogFormatter */ public function getLogFormatter() - { + { if(!$this->log_formatter) { $this->setLogFormatter(new LogFormatter); } @@ -296,4 +306,13 @@ public function setOptions(array $options=null) } } -} \ No newline at end of file + /** + * Check if log is empty + * + * @return bool + */ + public function isEmpty() : bool + { + return $this->empty; + } +} diff --git a/src/Logger/ErrorLog.php b/src/Logger/ErrorLog.php index 08bbec5..05a7d70 100644 --- a/src/Logger/ErrorLog.php +++ b/src/Logger/ErrorLog.php @@ -77,4 +77,13 @@ public function write(LogEntry $log) ); } -} \ No newline at end of file + /** + * Get log destination + * + * @return string|null + */ + public function getDestination() : string|null + { + return $this->destination; + } +} diff --git a/src/Logger/File.php b/src/Logger/File.php index f732542..1e0e177 100644 --- a/src/Logger/File.php +++ b/src/Logger/File.php @@ -19,7 +19,6 @@ */ class File extends ErrorLog { - /** * Constructor. * @@ -42,5 +41,4 @@ public function __construct($file) $this->destination = $file; $this->type = static::FILE; } - }