Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #33241 [Monolog] Fixed ElasticsearchLogstashHandler with monolog …
…2+ (lyrixx) This PR was merged into the 4.4 branch. Discussion ---------- [Monolog] Fixed ElasticsearchLogstashHandler with monolog 2+ | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- 1f4ca61 [Monolog] Fixed ElasticsearchLogstashHandler with monolog 2+
- Loading branch information
Showing
4 changed files
with
179 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/Symfony/Bridge/Monolog/Handler/FormattableHandlerTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
/* | ||
* This file is part of the Monolog package. | ||
* | ||
* (c) Jordi Boggiano <j.boggiano@seld.be> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Monolog\Handler; | ||
|
||
use Monolog\Formatter\FormatterInterface; | ||
use Monolog\Formatter\LineFormatter; | ||
|
||
/** | ||
* Helper trait for implementing FormattableInterface. | ||
* | ||
* @author Jordi Boggiano <j.boggiano@seld.be> | ||
* | ||
* @internal | ||
*/ | ||
trait FormattableHandlerTrait | ||
{ | ||
/** | ||
* @var FormatterInterface | ||
*/ | ||
protected $formatter; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @suppress PhanTypeMismatchReturn | ||
*/ | ||
public function setFormatter(FormatterInterface $formatter): HandlerInterface | ||
{ | ||
$this->formatter = $formatter; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFormatter(): FormatterInterface | ||
{ | ||
if (!$this->formatter) { | ||
$this->formatter = $this->getDefaultFormatter(); | ||
} | ||
|
||
return $this->formatter; | ||
} | ||
|
||
/** | ||
* Gets the default formatter. | ||
* | ||
* Overwrite this if the LineFormatter is not a good default for your handler. | ||
*/ | ||
protected function getDefaultFormatter(): FormatterInterface | ||
{ | ||
return new LineFormatter(); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/Symfony/Bridge/Monolog/Handler/ProcessableHandlerTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Bridge\Monolog\Handler; | ||
|
||
use Monolog\ResettableInterface; | ||
|
||
/** | ||
* Helper trait for implementing ProcessableInterface. | ||
* | ||
* @author Jordi Boggiano <j.boggiano@seld.be> | ||
* | ||
* @internal | ||
*/ | ||
trait ProcessableHandlerTrait | ||
{ | ||
/** | ||
* @var callable[] | ||
*/ | ||
protected $processors = []; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @suppress PhanTypeMismatchReturn | ||
*/ | ||
public function pushProcessor($callback): HandlerInterface | ||
{ | ||
array_unshift($this->processors, $callback); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function popProcessor(): callable | ||
{ | ||
if (!$this->processors) { | ||
throw new \LogicException('You tried to pop from an empty processor stack.'); | ||
} | ||
|
||
return array_shift($this->processors); | ||
} | ||
|
||
/** | ||
* Processes a record. | ||
*/ | ||
protected function processRecord(array $record): array | ||
{ | ||
foreach ($this->processors as $processor) { | ||
$record = $processor($record); | ||
} | ||
|
||
return $record; | ||
} | ||
|
||
protected function resetProcessors() | ||
{ | ||
foreach ($this->processors as $processor) { | ||
if ($processor instanceof ResettableInterface) { | ||
$processor->reset(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters