1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-22 17:16:18 +02:00

Code cleanups

This commit is contained in:
Jordi Boggiano
2022-03-05 14:03:57 +01:00
parent b586dbe8e6
commit 5eb9b8ed93
109 changed files with 418 additions and 549 deletions

View File

@@ -47,11 +47,11 @@ class GitProcessor implements ProcessorInterface
public function __invoke(LogRecord $record): LogRecord
{
// return if the level is not high enough
if ($record['level'] < $this->level) {
if ($record->level < $this->level) {
return $record;
}
$record['extra']['git'] = self::getGitInfo();
$record->extra['git'] = self::getGitInfo();
return $record;
}

View File

@@ -31,7 +31,7 @@ class HostnameProcessor implements ProcessorInterface
*/
public function __invoke(LogRecord $record): LogRecord
{
$record['extra']['hostname'] = self::$host;
$record->extra['hostname'] = self::$host;
return $record;
}

View File

@@ -31,14 +31,14 @@ use Monolog\LogRecord;
*/
class IntrospectionProcessor implements ProcessorInterface
{
/** @var int */
private $level;
private int $level;
/** @var string[] */
private $skipClassesPartials;
/** @var int */
private $skipStackFramesCount;
/** @var string[] */
private $skipFunctions = [
private array $skipClassesPartials;
private int $skipStackFramesCount;
private const SKIP_FUNCTIONS = [
'call_user_func',
'call_user_func_array',
];
@@ -62,7 +62,7 @@ class IntrospectionProcessor implements ProcessorInterface
public function __invoke(LogRecord $record): LogRecord
{
// return if the level is not high enough
if ($record['level'] < $this->level) {
if ($record->level < $this->level) {
return $record;
}
@@ -84,7 +84,7 @@ class IntrospectionProcessor implements ProcessorInterface
continue 2;
}
}
} elseif (in_array($trace[$i]['function'], $this->skipFunctions)) {
} elseif (in_array($trace[$i]['function'], self::SKIP_FUNCTIONS)) {
$i++;
continue;
@@ -96,8 +96,8 @@ class IntrospectionProcessor implements ProcessorInterface
$i += $this->skipStackFramesCount;
// we should have the call source now
$record['extra'] = array_merge(
$record['extra'],
$record->extra = array_merge(
$record->extra,
[
'file' => isset($trace[$i - 1]['file']) ? $trace[$i - 1]['file'] : null,
'line' => isset($trace[$i - 1]['line']) ? $trace[$i - 1]['line'] : null,
@@ -111,7 +111,7 @@ class IntrospectionProcessor implements ProcessorInterface
}
/**
* @param array[] $trace
* @param array<mixed> $trace
*/
private function isTraceClassOrSkippedFunction(array $trace, int $index): bool
{
@@ -119,6 +119,6 @@ class IntrospectionProcessor implements ProcessorInterface
return false;
}
return isset($trace[$index]['class']) || in_array($trace[$index]['function'], $this->skipFunctions);
return isset($trace[$index]['class']) || in_array($trace[$index]['function'], self::SKIP_FUNCTIONS);
}
}

View File

@@ -32,7 +32,7 @@ class MemoryPeakUsageProcessor extends MemoryProcessor
$usage = $this->formatBytes($usage);
}
$record['extra']['memory_peak_usage'] = $usage;
$record->extra['memory_peak_usage'] = $usage;
return $record;
}

View File

@@ -32,7 +32,7 @@ class MemoryUsageProcessor extends MemoryProcessor
$usage = $this->formatBytes($usage);
}
$record['extra']['memory_usage'] = $usage;
$record->extra['memory_usage'] = $usage;
return $record;
}

View File

@@ -46,11 +46,11 @@ class MercurialProcessor implements ProcessorInterface
public function __invoke(LogRecord $record): LogRecord
{
// return if the level is not high enough
if ($record['level'] < $this->level) {
if ($record->level < $this->level) {
return $record;
}
$record['extra']['hg'] = self::getMercurialInfo();
$record->extra['hg'] = self::getMercurialInfo();
return $record;
}

View File

@@ -25,7 +25,7 @@ class ProcessIdProcessor implements ProcessorInterface
*/
public function __invoke(LogRecord $record): LogRecord
{
$record['extra']['process_id'] = getmypid();
$record->extra['process_id'] = getmypid();
return $record;
}

View File

@@ -46,16 +46,16 @@ class PsrLogMessageProcessor implements ProcessorInterface
*/
public function __invoke(LogRecord $record): LogRecord
{
if (false === strpos($record['message'], '{')) {
if (false === strpos($record->message, '{')) {
return $record;
}
$replacements = [];
$context = $record['context'];
$context = $record->context;
foreach ($context as $key => $val) {
$placeholder = '{' . $key . '}';
if (strpos($record['message'], $placeholder) === false) {
if (strpos($record->message, $placeholder) === false) {
continue;
}
@@ -82,6 +82,6 @@ class PsrLogMessageProcessor implements ProcessorInterface
}
}
return $record->with(message: strtr($record['message'], $replacements), context: $context);
return $record->with(message: strtr($record->message, $replacements), context: $context);
}
}

View File

@@ -38,7 +38,7 @@ class UidProcessor implements ProcessorInterface, ResettableInterface
*/
public function __invoke(LogRecord $record): LogRecord
{
$record['extra']['uid'] = $this->uid;
$record->extra['uid'] = $this->uid;
return $record;
}

View File

@@ -86,7 +86,7 @@ class WebProcessor implements ProcessorInterface
return $record;
}
$record['extra'] = $this->appendExtraFields($record['extra']);
$record->extra = $this->appendExtraFields($record->extra);
return $record;
}