Fix compatibility with Monolog 2

This commit is contained in:
Jérémy Derussé 2019-11-28 17:00:16 +01:00
parent 7c7d98135a
commit bdb10f7cd5
No known key found for this signature in database
GPG Key ID: 2083FA5758C473D2

View File

@ -12,14 +12,43 @@
namespace Symfony\Bridge\Monolog\Handler;
use Monolog\Formatter\FormatterInterface;
use Monolog\Handler\AbstractHandler;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Handler\FormattableHandlerTrait;
use Monolog\Logger;
use Symfony\Bridge\Monolog\Formatter\VarDumperFormatter;
if (trait_exists(FormattableHandlerTrait::class)) {
class ServerLogHandler extends AbstractProcessingHandler
{
use ServerLogHandlerTrait;
/**
* {@inheritdoc}
*/
protected function getDefaultFormatter(): FormatterInterface
{
return new VarDumperFormatter();
}
}
} else {
class ServerLogHandler extends AbstractProcessingHandler
{
use ServerLogHandlerTrait;
/**
* {@inheritdoc}
*/
protected function getDefaultFormatter()
{
return new VarDumperFormatter();
}
}
}
/**
* @author Grégoire Pineau <lyrixx@lyrixx.info>
*/
class ServerLogHandler extends AbstractHandler
trait ServerLogHandlerTrait
{
private $host;
private $context;
@ -56,6 +85,11 @@ class ServerLogHandler extends AbstractHandler
restore_error_handler();
}
return parent::handle($record);
}
protected function write(array $record): void
{
$recordFormatted = $this->formatRecord($record);
set_error_handler(self::class.'::nullErrorHandler');
@ -72,16 +106,12 @@ class ServerLogHandler extends AbstractHandler
} finally {
restore_error_handler();
}
return false === $this->bubble;
}
/**
* {@inheritdoc}
*
* @return FormatterInterface
*/
protected function getDefaultFormatter()
protected function getDefaultFormatter(): FormatterInterface
{
return new VarDumperFormatter();
}
@ -103,13 +133,7 @@ class ServerLogHandler extends AbstractHandler
private function formatRecord(array $record): string
{
if ($this->processors) {
foreach ($this->processors as $processor) {
$record = $processor($record);
}
}
$recordFormatted = $this->getFormatter()->format($record);
$recordFormatted = $record['formatted'];
foreach (['log_uuid', 'uuid', 'uid'] as $key) {
if (isset($record['extra'][$key])) {