Skip to content

Commit 145c2ee

Browse files
committed
fixed #499 - added Monolog V3 Handler
1 parent 5dee03c commit 145c2ee

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/JiraClient.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,18 @@ public function __construct(ConfigurationInterface $configuration = null, Logger
9292
}
9393
} else {
9494
$this->log = new Logger('JiraClient');
95-
$this->log->pushHandler(new NoOperationMonologHandler());
95+
96+
// Monolog 3.x has a breaking change, so I have to add this dirty code.
97+
$ver = \Composer\InstalledVersions::getVersion('monolog/monolog');
98+
$major = intval(explode('.', $ver)[0]);
99+
100+
if ($major === 2) {
101+
$this->log->pushHandler(new NoOperationMonologHandler());
102+
} elseif ($major === 3) {
103+
$this->log->pushHandler(new NoOperationMonologHandlerV3());
104+
} else {
105+
throw new JiraException("Unsupported Monolog version $major");
106+
}
96107
}
97108

98109
$this->http_response = 200;

src/NoOperationMonologHandlerV3.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace JiraRestApi;
4+
5+
use Monolog\Handler\AbstractProcessingHandler;
6+
use Monolog\LogRecord;
7+
8+
class NoOperationMonologHandlerV3 extends AbstractProcessingHandler
9+
{
10+
protected function write(LogRecord $record): void
11+
{
12+
// do nothing
13+
}
14+
}

0 commit comments

Comments
 (0)