Fix compatibility with Monolog 2
This commit is contained in:
parent
7c7d98135a
commit
bdb10f7cd5
@ -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])) {
|
||||
|
Reference in New Issue
Block a user