qqq
This commit is contained in:
@@ -4,7 +4,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Kiri\Error;
|
namespace Kiri\Error;
|
||||||
|
|
||||||
use Kiri\Abstracts\BaseApplication;
|
|
||||||
use Kiri\Abstracts\Component;
|
use Kiri\Abstracts\Component;
|
||||||
use Monolog\Handler\StreamHandler;
|
use Monolog\Handler\StreamHandler;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
@@ -39,13 +38,23 @@ class StdoutLogger extends Component
|
|||||||
*/
|
*/
|
||||||
protected Logger $logger;
|
protected Logger $logger;
|
||||||
|
|
||||||
|
protected array $levels;
|
||||||
|
|
||||||
/**
|
public function __construct()
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function init(): void
|
|
||||||
{
|
{
|
||||||
|
parent::__construct();
|
||||||
|
|
||||||
$this->logger = new Logger(\config('id'));
|
$this->logger = new Logger(\config('id'));
|
||||||
|
$this->levels = [
|
||||||
|
'debug' => $this->logger::DEBUG,
|
||||||
|
'info' => $this->logger::INFO,
|
||||||
|
'notice' => $this->logger::NOTICE,
|
||||||
|
'warning' => $this->logger::WARNING,
|
||||||
|
'error' => $this->logger::ERROR,
|
||||||
|
'critical' => $this->logger::CRITICAL,
|
||||||
|
'alert' => $this->logger::ALERT,
|
||||||
|
'emergency' => $this->logger::EMERGENCY,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -74,21 +83,28 @@ class StdoutLogger extends Component
|
|||||||
*/
|
*/
|
||||||
public function __call(string $name, array $arguments)
|
public function __call(string $name, array $arguments)
|
||||||
{
|
{
|
||||||
// TODO: Implement __call() method.
|
try {
|
||||||
if (!isset($arguments[2])) {
|
if (method_exists($this->logger, $name)) {
|
||||||
$arguments[2] = [];
|
$this->createHandler($name)->$name(...$arguments);
|
||||||
|
} else if (method_exists($this, $name)) {
|
||||||
|
$this->{$name}(...$arguments);
|
||||||
|
}
|
||||||
|
} catch (\Throwable $exception) {
|
||||||
|
echo $exception->getMessage() . PHP_EOL;
|
||||||
}
|
}
|
||||||
[$level, $message, $context] = $arguments;
|
}
|
||||||
|
|
||||||
$levels = \config('log.level', BaseApplication::LOGGER_LEVELS);
|
|
||||||
if (!in_array($level, $levels)) {
|
/**
|
||||||
return;
|
* @param string $name
|
||||||
|
* @return Logger
|
||||||
|
*/
|
||||||
|
protected function createHandler(string $name): Logger
|
||||||
|
{
|
||||||
|
if (!$this->logger->isHandling($this->levels[$name])) {
|
||||||
|
$this->logger->pushHandler(new StreamHandler(APP_PATH . 'storage/logs/' . $name . '/' . date('Y-m-d') . '.log', $this->levels[$name]));
|
||||||
}
|
}
|
||||||
if (!$this->logger->isHandling($level)) {
|
return $this->logger;
|
||||||
$path = APP_PATH . 'storage/logs/' . strtolower(Logger::getLevelName($level)) . '/' . date('Y-m-d') . '.log';
|
|
||||||
$this->logger->pushHandler(new StreamHandler($path, $level));
|
|
||||||
}
|
|
||||||
$this->logger->{$name}($level, $message, $context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user