Skip to content

Commit 14c0914

Browse files
committed
#8, #24 Support to Monolog v2 and v3 both for running Laravel.
1 parent af0efa2 commit 14c0914

3 files changed

Lines changed: 27 additions & 2 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"ext-curl": "*",
99
"ext-json": "*",
1010
"netresearch/jsonmapper": "^3.0|^4.0|^5.0",
11-
"monolog/monolog": "^3.0",
11+
"monolog/monolog": "^2.0|^3.0",
1212
"vlucas/phpdotenv": "^5.0|^6.0",
1313
"damienharper/adf-tools": "^1.0"
1414
},

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;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace JiraCloud;
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)