Skip to content
Permalink
Browse files

feature #27905 [MonologBridge] Monolog 2 compatibility (derrabus)

This PR was merged into the 5.0-dev branch.

Discussion
----------

[MonologBridge] Monolog 2 compatibility

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #27857
| License       | MIT
| Doc PR        | N/A

See #27857 for the discussion.

This PR adds return types to methods that need to have one in Monolog 2.

Notes:
* The PR will break userland handlers that extend handlers from Monolog Bridge.
* I was unable to come up with a php 7.1 compatible version of `SwiftMailerHandler` that works with Monolog 1 and Monolog 2 because a method we're overriding now has a `string` type-hint on a parameter that wasn't there before. I've „solved“ this with a version switch, but I feel dirty doing this. 🙈  If you have a better solution, please enlighten me.

Commits
-------

ca1cfec Monolog 2 compatibility.
  • Loading branch information...
fabpot committed Jul 8, 2019
2 parents e9a2e3f + ca1cfec commit 40d04ec37ba2606b2074268eceb321d323293f38
@@ -108,7 +108,7 @@
"doctrine/reflection": "~1.0",
"doctrine/doctrine-bundle": "^1.5|^2.0",
"masterminds/html5": "^2.6",
"monolog/monolog": "~1.11",
"monolog/monolog": "^1.11|^2",
"nyholm/psr7": "^1.0",
"ocramius/proxy-manager": "^2.1",
"php-http/httplug": "^1.0|^2.0",
@@ -5,6 +5,7 @@ CHANGELOG
-----

* The methods `DebugProcessor::getLogs()`, `DebugProcessor::countErrors()`, `Logger::getLogs()` and `Logger::countErrors()` have a new `$request` argument.
* Added support for Monolog 2.

4.4.0
-----
@@ -57,7 +57,7 @@ public function onKernelResponse(ResponseEvent $event)
/**
* {@inheritdoc}
*/
protected function sendHeader($header, $content)
protected function sendHeader($header, $content): void
{
if (!$this->sendHeaders) {
return;
@@ -11,6 +11,7 @@
namespace Symfony\Bridge\Monolog\Handler;
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Logger;
@@ -74,15 +75,15 @@ public function __construct(OutputInterface $output = null, bool $bubble = true,
/**
* {@inheritdoc}
*/
public function isHandling(array $record)
public function isHandling(array $record): bool
{
return $this->updateLevel() && parent::isHandling($record);
}
/**
* {@inheritdoc}
*/
public function handle(array $record)
public function handle(array $record): bool
{
// we have to update the logging level each time because the verbosity of the
// console output might have changed in the meantime (it is not immutable)
@@ -100,7 +101,7 @@ public function setOutput(OutputInterface $output)
/**
* Disables the output.
*/
public function close()
public function close(): void
{
$this->output = null;
@@ -143,7 +144,7 @@ public static function getSubscribedEvents()
/**
* {@inheritdoc}
*/
protected function write(array $record)
protected function write(array $record): void
{
// at this point we've determined for sure that we want to output the record, so use the output's own verbosity
$this->output->write((string) $record['formatted'], false, $this->output->getVerbosity());
@@ -152,7 +153,7 @@ protected function write(array $record)
/**
* {@inheritdoc}
*/
protected function getDefaultFormatter()
protected function getDefaultFormatter(): FormatterInterface
{
if (!class_exists(CliDumper::class)) {
return new LineFormatter();
@@ -45,7 +45,7 @@ public function __construct(RequestStack $requestStack, array $exclusions, $acti
$this->exclusions = $exclusions;
}
public function isHandlerActivated(array $record)
public function isHandlerActivated(array $record): bool
{
$isActivated = parent::isHandlerActivated($record);
@@ -34,7 +34,7 @@ public function __construct(RequestStack $requestStack, array $excludedUrls, $ac
$this->blacklist = '{('.implode('|', $excludedUrls).')}i';
}
public function isHandlerActivated(array $record)
public function isHandlerActivated(array $record): bool
{
$isActivated = parent::isHandlerActivated($record);
@@ -59,7 +59,7 @@ public function onKernelResponse(ResponseEvent $event)
/**
* {@inheritdoc}
*/
protected function sendHeader($header, $content)
protected function sendHeader($header, $content): void
{
if (!self::$sendHeaders) {
return;
@@ -39,7 +39,7 @@ public function __construct(string $host, int $level = Logger::DEBUG, bool $bubb
/**
* {@inheritdoc}
*/
public function handle(array $record)
public function handle(array $record): bool
{
if (!$this->isHandling($record)) {
return false;
@@ -52,7 +52,7 @@ public function onCliTerminate(ConsoleTerminateEvent $event)
/**
* {@inheritdoc}
*/
protected function send($content, array $records)
protected function send($content, array $records): void
{
parent::send($content, $records);
@@ -59,7 +59,7 @@ public function clear()
/**
* {@inheritdoc}
*/
public function reset()
public function reset(): void
{
$this->clear();
@@ -17,7 +17,7 @@
],
"require": {
"php": "^7.2.9",
"monolog/monolog": "~1.19",
"monolog/monolog": "^1.19|^2",
"symfony/service-contracts": "^1.1",
"symfony/http-kernel": "^4.4|^5.0"
},

0 comments on commit 40d04ec

Please sign in to comment.
You can’t perform that action at this time.