qqq
This commit is contained in:
@@ -16,14 +16,15 @@ use Kiri;
|
||||
use Kiri\Events\EventInterface;
|
||||
use Kiri\Di\LocalService;
|
||||
use Kiri\Config\ConfigProvider;
|
||||
use Kiri\Error\StdoutLogger;
|
||||
use Kiri\Exception\{InitException};
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Kiri\Events\EventProvider;
|
||||
use ReflectionException;
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* Class BaseApplication
|
||||
@@ -75,17 +76,27 @@ abstract class BaseApplication extends Component
|
||||
$this->mapping($config);
|
||||
$this->parseStorage($config);
|
||||
$this->parseEvents($config);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
const LOGGER_LEVELS = [Logger::EMERGENCY, Logger::ALERT, Logger::CRITICAL, Logger::ERROR, Logger::WARNING, Logger::NOTICE, Logger::INFO, Logger::DEBUG];
|
||||
|
||||
/**
|
||||
* @param ConfigProvider $config
|
||||
* @return void
|
||||
*/
|
||||
public function mapping(ConfigProvider $config): void
|
||||
{
|
||||
$this->container->set(LoggerInterface::class, StdoutLogger::class);
|
||||
$this->container->bind(LoggerInterface::class, $logger = new Logger($config->get('id')));
|
||||
$levels = \config('log.level', self::LOGGER_LEVELS);
|
||||
|
||||
foreach ($levels as $level) {
|
||||
$run = new StreamHandler(APP_PATH . 'storage/logs/' . $level . '/' . date('Y-m-d') . '.log', $level);
|
||||
$logger->pushHandler($run);
|
||||
}
|
||||
|
||||
foreach ($config->get('mapping', []) as $interface => $class) {
|
||||
$this->container->set($interface, $class);
|
||||
}
|
||||
|
||||
@@ -4,13 +4,10 @@ namespace Kiri\Abstracts;
|
||||
|
||||
use DirectoryIterator;
|
||||
use Exception;
|
||||
use Kiri\Events\EventProvider;
|
||||
use Kiri\Exception\ConfigException;
|
||||
use Kiri;
|
||||
use Kiri\Server\Events\OnWorkerStop;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ReflectionException;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
|
||||
/**
|
||||
@@ -168,6 +165,16 @@ class Logger implements LoggerInterface
|
||||
*/
|
||||
public function log($level, $message, array $context = []): void
|
||||
{
|
||||
/** @var \Monolog\Logger $logger */
|
||||
$logger = Kiri::getDi()->get(LoggerInterface::class);
|
||||
|
||||
$logger->log($level, $message, $context);
|
||||
|
||||
$run = new StreamHandler(APP_PATH . 'storage/logs/' . date('Y-m-d') . '/'.date('Y-m-d').'.log');
|
||||
$logger->pushHandler($run);
|
||||
|
||||
|
||||
|
||||
if (!in_array($level, $this->levels)) return;
|
||||
$_string = "[" . now() . ']: ' . $message;
|
||||
if (!empty($context)) {
|
||||
|
||||
@@ -17,7 +17,6 @@ use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use ReflectionException;
|
||||
use Kiri\Abstracts\Logger;
|
||||
use Kiri\Events\OnSystemError;
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,9 +4,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace Kiri\Error;
|
||||
|
||||
use Kiri\Abstracts\Logger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ReflectionException;
|
||||
|
||||
class StdoutLogger extends Logger
|
||||
class StdoutLogger
|
||||
{
|
||||
|
||||
|
||||
@@ -16,11 +17,12 @@ class StdoutLogger extends Logger
|
||||
private array $errors = [];
|
||||
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
* @param string $model
|
||||
* @return bool
|
||||
*/
|
||||
/**
|
||||
* @param $message
|
||||
* @param string $model
|
||||
* @return bool
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function failure($message, string $model = 'app'): bool
|
||||
{
|
||||
if ($message instanceof \Exception) {
|
||||
@@ -28,7 +30,8 @@ class StdoutLogger extends Logger
|
||||
} else {
|
||||
$this->errors[$model] = $message;
|
||||
}
|
||||
$this->error(throwable($message), []);
|
||||
$logger = \Kiri::getDi()->get(LoggerInterface::class);
|
||||
$logger->error(throwable($message), []);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user