diff --git a/composer.json b/composer.json index 3df7d57..24f51c6 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,10 @@ "quillstack/unit-tests": "^0.2.15" }, "require": { - "psr/log": "^3.0" + "ext-json": "*", + "psr/log": "^3.0", + "quillstack/di": "^0.0.8", + "quillstack/local-storage": "^0.0.6" }, "extra": { "branch-alias": { diff --git a/src/Exceptions/HandlerNotSetException.php b/src/Exceptions/HandlerNotSetException.php new file mode 100644 index 0000000..8a9d193 --- /dev/null +++ b/src/Exceptions/HandlerNotSetException.php @@ -0,0 +1,12 @@ +localStorage->save($this->path, $line); + } +} diff --git a/src/Logger.php b/src/Logger.php new file mode 100644 index 0000000..ef45ac1 --- /dev/null +++ b/src/Logger.php @@ -0,0 +1,98 @@ +handler = $handler; + } + + /** + * {@inheritDoc} + */ + public function emergency(\Stringable|string $message, array $context = []): void + { + $this->log(LogLevel::EMERGENCY, $message, $context); + } + + /** + * {@inheritDoc} + */ + public function alert(\Stringable|string $message, array $context = []): void + { + $this->log(LogLevel::ALERT, $message, $context); + } + + /** + * {@inheritDoc} + */ + public function critical(\Stringable|string $message, array $context = []): void + { + $this->log(LogLevel::CRITICAL, $message, $context); + } + + /** + * {@inheritDoc} + */ + public function error(\Stringable|string $message, array $context = []): void + { + $this->log(LogLevel::ERROR, $message, $context); + } + + /** + * {@inheritDoc} + */ + public function warning(\Stringable|string $message, array $context = []): void + { + $this->log(LogLevel::WARNING, $message, $context); + } + + /** + * {@inheritDoc} + */ + public function notice(\Stringable|string $message, array $context = []): void + { + $this->log(LogLevel::NOTICE, $message, $context); + } + + /** + * {@inheritDoc} + */ + public function info(\Stringable|string $message, array $context = []): void + { + $this->log(LogLevel::INFO, $message, $context); + } + + /** + * {@inheritDoc} + */ + public function debug(\Stringable|string $message, array $context = []): void + { + $this->log(LogLevel::DEBUG, $message, $context); + } + + /** + * {@inheritDoc} + */ + public function log($level, \Stringable|string $message, array $context = []): void + { + if ($this->handler === null) { + throw new HandlerNotSetException(); + } + + $this->handler->log($level, $message, $context); + } +} diff --git a/src/LoggerException.php b/src/LoggerException.php new file mode 100644 index 0000000..37d843e --- /dev/null +++ b/src/LoggerException.php @@ -0,0 +1,10 @@ +