Skip to content

Commit f0a0d21

Browse files
committed
fix(#676): set monolog handler by checking the constant Monolog\Logger::API
1 parent 77e3186 commit f0a0d21

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

Clockwork/DataSource/MonologDataSource.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
use Clockwork\DataSource\DataSource;
44
use Clockwork\Request\Log;
55
use Clockwork\Request\Request;
6-
use Clockwork\Support\Monolog\Monolog2\ClockworkHandler;
7-
use Clockwork\Support\Monolog\Monolog\ClockworkHandler as MonologClockworkHandler;
8-
use Monolog\Handler\AbstractProcessingHandler;
6+
use Clockwork\Support\Monolog\Monolog2\ClockworkHandler as Monolog2ClockworkHandler;
7+
use Clockwork\Support\Monolog\Monolog\ClockworkHandler;
98
use Monolog\Logger as Monolog;
10-
use ReflectionMethod;
119

1210
// Data source for Monolog, provides application log
1311
class MonologDataSource extends DataSource
@@ -20,17 +18,21 @@ public function __construct(Monolog $monolog)
2018
{
2119
$this->log = new Log;
2220

23-
/**
24-
* Use `Clockwork\Support\Monolog\Monolog2\ClockworkHandler`
25-
* when the method `AbstractProcessingHandler::write` has a return type
26-
* Because Monolog 2 introduced scalar type hints and return hints
27-
*/
28-
$writeMethod = new ReflectionMethod(AbstractProcessingHandler::class, 'write');
29-
if ($writeMethod->hasReturnType()) {
30-
$monolog->pushHandler(new ClockworkHandler($this->log));
31-
} else {
32-
$monolog->pushHandler(new MonologClockworkHandler($this->log));
21+
$handler=null;
22+
switch (\Monolog\Logger::API) {
23+
case 1:
24+
$handler=new ClockworkHandler($this->log);
25+
break;
26+
case 2:
27+
$handler=new Monolog2ClockworkHandler($this->log);
28+
break;
29+
default:
30+
// By default use the latest implementation of clockwork handler
31+
$handler=new Monolog2ClockworkHandler($this->log);
32+
break;
3333
}
34+
35+
$monolog->pushHandler($handler);
3436
}
3537

3638
// Adds log entries to the request

0 commit comments

Comments
 (0)