33use Clockwork \DataSource \DataSource ;
44use Clockwork \Request \Log ;
55use 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 ;
98use Monolog \Logger as Monolog ;
10- use ReflectionMethod ;
119
1210// Data source for Monolog, provides application log
1311class 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