Files
kiri-core/kiri-engine/Error/StdoutLogger.php
T

49 lines
841 B
PHP
Raw Normal View History

2022-02-23 16:32:08 +08:00
<?php
2023-04-16 01:45:34 +08:00
declare(strict_types=1);
2022-02-23 16:32:08 +08:00
namespace Kiri\Error;
2023-08-14 21:09:45 +08:00
use Psr\Log\LoggerInterface;
use ReflectionException;
2022-02-23 16:32:08 +08:00
2023-08-14 21:09:45 +08:00
class StdoutLogger
2022-02-23 16:32:08 +08:00
{
2023-04-05 15:22:01 +08:00
/**
* @var array
*/
2022-02-23 16:32:08 +08:00
private array $errors = [];
2023-08-14 21:09:45 +08:00
/**
* @param $message
* @param string $model
* @return bool
* @throws ReflectionException
*/
2023-07-31 23:09:00 +08:00
public function failure($message, string $model = 'app'): bool
2022-02-23 16:32:08 +08:00
{
if ($message instanceof \Exception) {
$this->errors[$model] = $message->getMessage();
} else {
$this->errors[$model] = $message;
2023-07-31 23:09:00 +08:00
}
2023-08-14 21:09:45 +08:00
$logger = \Kiri::getDi()->get(LoggerInterface::class);
$logger->error(throwable($message), []);
2023-07-31 23:09:00 +08:00
return false;
2022-02-23 16:32:08 +08:00
}
/**
* @param string $model
* @return mixed
*/
public function getLastError(string $model = 'app'): mixed
{
return $this->errors[$model] ?? 'Unknown error.';
}
}