diff --git a/composer.json b/composer.json index 978141d74..b5c3e6187 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "ext-simplexml": "*", "easywechat-composer/easywechat-composer": "^1.1", "guzzlehttp/guzzle": "^6.2", - "monolog/monolog": "^1.22", + "monolog/monolog": "^1.22 || ^2.0", "overtrue/socialite": "~2.0", "pimple/pimple": "^3.0", "psr/simple-cache": "^1.0", @@ -35,7 +35,7 @@ "mikey179/vfsstream": "^1.6", "mockery/mockery": "^1.0", "phpstan/phpstan": "^0.11.12", - "phpunit/phpunit": "~6.5" + "phpunit/phpunit": "^7.5" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index 2ef6bfd3b..3dfb456cf 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -7,8 +7,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" - syntaxCheck="false"> + stopOnFailure="false"> ./tests/ diff --git a/src/Kernel/Log/LogManager.php b/src/Kernel/Log/LogManager.php index 8fba3aa6c..3d356ef53 100644 --- a/src/Kernel/Log/LogManager.php +++ b/src/Kernel/Log/LogManager.php @@ -14,6 +14,7 @@ use EasyWeChat\Kernel\ServiceContainer; use Monolog\Formatter\LineFormatter; use Monolog\Handler\ErrorLogHandler; +use Monolog\Handler\FormattableHandlerInterface; use Monolog\Handler\HandlerInterface; use Monolog\Handler\RotatingFileHandler; use Monolog\Handler\SlackWebhookHandler; @@ -81,6 +82,8 @@ public function __construct(ServiceContainer $app) * @param string|null $channel * * @return \Psr\Log\LoggerInterface + * + * @throws \Exception */ public function stack(array $channels, $channel = null) { @@ -93,6 +96,8 @@ public function stack(array $channels, $channel = null) * @param string|null $channel * * @return mixed + * + * @throws \Exception */ public function channel($channel = null) { @@ -105,6 +110,8 @@ public function channel($channel = null) * @param string|null $driver * * @return mixed + * + * @throws \Exception */ public function driver($driver = null) { @@ -117,6 +124,8 @@ public function driver($driver = null) * @param string $name * * @return \Psr\Log\LoggerInterface + * + * @throws \Exception */ protected function get($name) { @@ -195,6 +204,8 @@ protected function callCustomCreator(array $config) * @param array $config * * @return \Monolog\Logger + * + * @throws \Exception */ protected function createStackDriver(array $config) { @@ -321,7 +332,11 @@ protected function prepareHandlers(array $handlers) */ protected function prepareHandler(HandlerInterface $handler) { - return $handler->setFormatter($this->formatter()); + if ($handler instanceof FormattableHandlerInterface) { + $handler->setFormatter($this->formatter()); + } + + return $handler; } /** @@ -346,7 +361,7 @@ protected function formatter() */ protected function parseChannel(array $config) { - return $config['name'] ?? null; + return $config['name'] ?? 'EasyWeChat'; } /** @@ -411,6 +426,8 @@ public function extend($driver, \Closure $callback) * @param array $context * * @return mixed + * + * @throws \Exception */ public function emergency($message, array $context = []) { @@ -427,6 +444,8 @@ public function emergency($message, array $context = []) * @param array $context * * @return mixed + * + * @throws \Exception */ public function alert($message, array $context = []) { @@ -442,6 +461,8 @@ public function alert($message, array $context = []) * @param array $context * * @return mixed + * + * @throws \Exception */ public function critical($message, array $context = []) { @@ -456,6 +477,8 @@ public function critical($message, array $context = []) * @param array $context * * @return mixed + * + * @throws \Exception */ public function error($message, array $context = []) { @@ -472,6 +495,8 @@ public function error($message, array $context = []) * @param array $context * * @return mixed + * + * @throws \Exception */ public function warning($message, array $context = []) { @@ -485,6 +510,8 @@ public function warning($message, array $context = []) * @param array $context * * @return mixed + * + * @throws \Exception */ public function notice($message, array $context = []) { @@ -500,6 +527,8 @@ public function notice($message, array $context = []) * @param array $context * * @return mixed + * + * @throws \Exception */ public function info($message, array $context = []) { @@ -513,6 +542,8 @@ public function info($message, array $context = []) * @param array $context * * @return mixed + * + * @throws \Exception */ public function debug($message, array $context = []) { @@ -527,6 +558,8 @@ public function debug($message, array $context = []) * @param array $context * * @return mixed + * + * @throws \Exception */ public function log($level, $message, array $context = []) { @@ -540,6 +573,8 @@ public function log($level, $message, array $context = []) * @param array $parameters * * @return mixed + * + * @throws \Exception */ public function __call($method, $parameters) {