Skip to content

Commit

Permalink
Disable OpenSearch client logger for Pimcore X
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-moser committed Feb 26, 2024
1 parent 16fdb0a commit a3e29f5
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions src/LogHandler/Filter404Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,40 @@
use Monolog\Handler\AbstractHandler;
use Monolog\Level;
use Monolog\LogRecord;
use Pimcore\Version;

/**
* Ignores warning messages for 404 errors as they are spamming the logs
*
* @internal
*/
final class Filter404Handler extends AbstractHandler
{
private bool $ignoreNextResponseWarning = false;
if(Version::getMajorVersion() >= 11) {

public function isHandling(LogRecord $record): bool
/**
* Ignores warning messages for 404 errors as they are spamming the logs
*
* @internal
*/
final class Filter404Handler extends AbstractHandler
{
$ignore =
$record->level === Level::Warning
&& ($record->context['HTTP code'] ?? null) === 404;

if ($ignore) {
$this->ignoreNextResponseWarning = true;
} else {
$ignore = $this->ignoreNextResponseWarning
&& $record->level === Level::Warning
&& $record->message === 'Response';
$this->ignoreNextResponseWarning = false;
private bool $ignoreNextResponseWarning = false;

public function isHandling(LogRecord $record): bool

Check failure on line 32 in src/LogHandler/Filter404Handler.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Parameter #1 $record (Monolog\LogRecord) of method Pimcore\Bundle\OpenSearchClientBundle\LogHandler\Filter404Handler::isHandling() is not contravariant with parameter #1 $record (array) of method Monolog\Handler\HandlerInterface::isHandling().

Check failure on line 32 in src/LogHandler/Filter404Handler.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Parameter $record of method Pimcore\Bundle\OpenSearchClientBundle\LogHandler\Filter404Handler::isHandling() has invalid type Monolog\LogRecord.
{
$ignore =
$record->level === Level::Warning

Check failure on line 35 in src/LogHandler/Filter404Handler.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Access to constant Warning on an unknown class Monolog\Level.

Check failure on line 35 in src/LogHandler/Filter404Handler.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Access to property $level on an unknown class Monolog\LogRecord.
&& ($record->context['HTTP code'] ?? null) === 404;

Check failure on line 36 in src/LogHandler/Filter404Handler.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Access to property $context on an unknown class Monolog\LogRecord.

if ($ignore) {
$this->ignoreNextResponseWarning = true;
} else {
$ignore = $this->ignoreNextResponseWarning
&& $record->level === Level::Warning

Check failure on line 42 in src/LogHandler/Filter404Handler.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Access to constant Warning on an unknown class Monolog\Level.

Check failure on line 42 in src/LogHandler/Filter404Handler.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Access to property $level on an unknown class Monolog\LogRecord.
&& $record->message === 'Response';

Check failure on line 43 in src/LogHandler/Filter404Handler.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Access to property $message on an unknown class Monolog\LogRecord.
$this->ignoreNextResponseWarning = false;
}

return $ignore;
}

return $ignore;
}

public function handle(LogRecord $record): bool
{
return $this->isHandling($record);
public function handle(LogRecord $record): bool

Check failure on line 50 in src/LogHandler/Filter404Handler.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Parameter #1 $record (Monolog\LogRecord) of method Pimcore\Bundle\OpenSearchClientBundle\LogHandler\Filter404Handler::handle() is not contravariant with parameter #1 $record (array) of method Monolog\Handler\HandlerInterface::handle().

Check failure on line 50 in src/LogHandler/Filter404Handler.php

View workflow job for this annotation

GitHub Actions / Static Analysis with PHPStan (8.1, lowest, false)

Parameter $record of method Pimcore\Bundle\OpenSearchClientBundle\LogHandler\Filter404Handler::handle() has invalid type Monolog\LogRecord.
{
return $this->isHandling($record);
}
}
}

0 comments on commit a3e29f5

Please sign in to comment.