diff --git a/kiri-engine/Abstracts/BaseApplication.php b/kiri-engine/Abstracts/BaseApplication.php index 3f516473..fc08b859 100644 --- a/kiri-engine/Abstracts/BaseApplication.php +++ b/kiri-engine/Abstracts/BaseApplication.php @@ -24,6 +24,7 @@ use Psr\Log\LoggerInterface; use Kiri\Events\EventProvider; use ReflectionException; use Monolog\Logger; +use Kiri\Error\StdoutLogger; /** * Class BaseApplication @@ -88,7 +89,7 @@ abstract class BaseApplication extends Component */ public function mapping(ConfigProvider $config): void { - $this->container->bind(LoggerInterface::class, $logger = new Logger($config->get('id'))); + $this->container->bind(LoggerInterface::class, new StdoutLogger()); foreach ($config->get('mapping', []) as $interface => $class) { $this->container->set($interface, $class); } diff --git a/kiri-engine/Error/StdoutLogger.php b/kiri-engine/Error/StdoutLogger.php index 8abf057c..cb619874 100644 --- a/kiri-engine/Error/StdoutLogger.php +++ b/kiri-engine/Error/StdoutLogger.php @@ -5,8 +5,7 @@ declare(strict_types=1); namespace Kiri\Error; use Kiri\Abstracts\BaseApplication; -use Kiri\Application; -use Kiri\Di\Inject\Container; +use Kiri\Abstracts\Component; use Monolog\Handler\StreamHandler; use Monolog\Logger; use Psr\Log\LoggerInterface; @@ -15,8 +14,17 @@ use ReflectionException; /** * @see LoggerInterface + * @method error(string $message, array $context) + * @method log($level, $message, array $context = array()) + * @method debug($message, array $context = array()) + * @method info($message, array $context = array()) + * @method notice($message, array $context = array()) + * @method warning($message, array $context = array()) + * @method critical($message, array $context = array()) + * @method alert($message, array $context = array()) + * @method emergency($message, array $context = array()) */ -class StdoutLogger +class StdoutLogger extends Component { @@ -26,15 +34,25 @@ class StdoutLogger private array $errors = []; - #[Container(Logger::class)] - public Logger $logger; + /** + * @var Logger + */ + protected Logger $logger; + + + /** + * @return void + */ + public function init(): void + { + $this->logger = new Logger(\config('id')); + } /** * @param $message * @param string $model * @return bool - * @throws ReflectionException */ public function failure($message, string $model = 'app'): bool { @@ -43,8 +61,7 @@ class StdoutLogger } else { $this->errors[$model] = $message; } - $logger = \Kiri::getDi()->get(LoggerInterface::class); - $logger->error(throwable($message), []); + $this->error(throwable($message), []); return false; }