qqq
This commit is contained in:
@@ -24,6 +24,7 @@ use Psr\Log\LoggerInterface;
|
|||||||
use Kiri\Events\EventProvider;
|
use Kiri\Events\EventProvider;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
|
use Kiri\Error\StdoutLogger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class BaseApplication
|
* Class BaseApplication
|
||||||
@@ -88,7 +89,7 @@ abstract class BaseApplication extends Component
|
|||||||
*/
|
*/
|
||||||
public function mapping(ConfigProvider $config): void
|
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) {
|
foreach ($config->get('mapping', []) as $interface => $class) {
|
||||||
$this->container->set($interface, $class);
|
$this->container->set($interface, $class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Kiri\Error;
|
namespace Kiri\Error;
|
||||||
|
|
||||||
use Kiri\Abstracts\BaseApplication;
|
use Kiri\Abstracts\BaseApplication;
|
||||||
use Kiri\Application;
|
use Kiri\Abstracts\Component;
|
||||||
use Kiri\Di\Inject\Container;
|
|
||||||
use Monolog\Handler\StreamHandler;
|
use Monolog\Handler\StreamHandler;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
@@ -15,8 +14,17 @@ use ReflectionException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @see LoggerInterface
|
* @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 = [];
|
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 $message
|
||||||
* @param string $model
|
* @param string $model
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws ReflectionException
|
|
||||||
*/
|
*/
|
||||||
public function failure($message, string $model = 'app'): bool
|
public function failure($message, string $model = 'app'): bool
|
||||||
{
|
{
|
||||||
@@ -43,8 +61,7 @@ class StdoutLogger
|
|||||||
} else {
|
} else {
|
||||||
$this->errors[$model] = $message;
|
$this->errors[$model] = $message;
|
||||||
}
|
}
|
||||||
$logger = \Kiri::getDi()->get(LoggerInterface::class);
|
$this->error(throwable($message), []);
|
||||||
$logger->error(throwable($message), []);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user