Skip to content

Commit

Permalink
[WIP]Monolog 2.0 (w7corp#1678)
Browse files Browse the repository at this point in the history
* Monolog 2.0

* fix

* Monolog 2

* Apply fixes from StyleCI

[ci skip] [skip ci]
  • Loading branch information
mingyoung authored and overtrue committed Sep 9, 2019
1 parent 86b5152 commit 8271f1c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
Expand Down
39 changes: 37 additions & 2 deletions src/Kernel/Log/LogManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -93,6 +96,8 @@ public function stack(array $channels, $channel = null)
* @param string|null $channel
*
* @return mixed
*
* @throws \Exception
*/
public function channel($channel = null)
{
Expand All @@ -105,6 +110,8 @@ public function channel($channel = null)
* @param string|null $driver
*
* @return mixed
*
* @throws \Exception
*/
public function driver($driver = null)
{
Expand All @@ -117,6 +124,8 @@ public function driver($driver = null)
* @param string $name
*
* @return \Psr\Log\LoggerInterface
*
* @throws \Exception
*/
protected function get($name)
{
Expand Down Expand Up @@ -195,6 +204,8 @@ protected function callCustomCreator(array $config)
* @param array $config
*
* @return \Monolog\Logger
*
* @throws \Exception
*/
protected function createStackDriver(array $config)
{
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -346,7 +361,7 @@ protected function formatter()
*/
protected function parseChannel(array $config)
{
return $config['name'] ?? null;
return $config['name'] ?? 'EasyWeChat';
}

/**
Expand Down Expand Up @@ -411,6 +426,8 @@ public function extend($driver, \Closure $callback)
* @param array $context
*
* @return mixed
*
* @throws \Exception
*/
public function emergency($message, array $context = [])
{
Expand All @@ -427,6 +444,8 @@ public function emergency($message, array $context = [])
* @param array $context
*
* @return mixed
*
* @throws \Exception
*/
public function alert($message, array $context = [])
{
Expand All @@ -442,6 +461,8 @@ public function alert($message, array $context = [])
* @param array $context
*
* @return mixed
*
* @throws \Exception
*/
public function critical($message, array $context = [])
{
Expand All @@ -456,6 +477,8 @@ public function critical($message, array $context = [])
* @param array $context
*
* @return mixed
*
* @throws \Exception
*/
public function error($message, array $context = [])
{
Expand All @@ -472,6 +495,8 @@ public function error($message, array $context = [])
* @param array $context
*
* @return mixed
*
* @throws \Exception
*/
public function warning($message, array $context = [])
{
Expand All @@ -485,6 +510,8 @@ public function warning($message, array $context = [])
* @param array $context
*
* @return mixed
*
* @throws \Exception
*/
public function notice($message, array $context = [])
{
Expand All @@ -500,6 +527,8 @@ public function notice($message, array $context = [])
* @param array $context
*
* @return mixed
*
* @throws \Exception
*/
public function info($message, array $context = [])
{
Expand All @@ -513,6 +542,8 @@ public function info($message, array $context = [])
* @param array $context
*
* @return mixed
*
* @throws \Exception
*/
public function debug($message, array $context = [])
{
Expand All @@ -527,6 +558,8 @@ public function debug($message, array $context = [])
* @param array $context
*
* @return mixed
*
* @throws \Exception
*/
public function log($level, $message, array $context = [])
{
Expand All @@ -540,6 +573,8 @@ public function log($level, $message, array $context = [])
* @param array $parameters
*
* @return mixed
*
* @throws \Exception
*/
public function __call($method, $parameters)
{
Expand Down

0 comments on commit 8271f1c

Please sign in to comment.