diff --git a/doc/01-usage.md b/doc/01-usage.md index 52deef6d..89e0fe7f 100644 --- a/doc/01-usage.md +++ b/doc/01-usage.md @@ -140,7 +140,7 @@ write a processor adding some dummy data in the record: pushProcessor(function ($record) { - $record['extra']['dummy'] = 'Hello world!'; + $record->extra['dummy'] = 'Hello world!'; return $record; }); @@ -190,23 +190,23 @@ $securityLogger = $logger->withName('security'); ## Customizing the log format In Monolog it's easy to customize the format of the logs written into files, -sockets, mails, databases and other handlers; by the use of "Formatters". +sockets, mails, databases and other handlers; by the use of "Formatters". As mentioned before, a *Formatter* is attached to a *Handler*, and as a general convention, most of the handlers use the ```php -$record['formatted'] +$record->formatted ``` field in the log record to store its formatted value. Again, this field depends on the implementation of the *Handler* but is a good idea to **stick into the good practices and conventions of the project**. You can choose between predefined formatter classes or write your own (e.g. a multiline text file for human-readable output). > Note: -> +> > A very useful formatter to look at, is the `LineFormatter`. -> +> > This formatter, as its name might indicate, is able to return a lineal string representation of the log record provided. > -> It is also capable to interpolate values from the log record, into the output format template used by the formatter to generate the final result, and in order to do it, you need to provide the log record values you are interested in, in the output template string using the form %value%, e.g: "'%context.foo% => %extra.foo%'", in this example the values $record["context"]["foo"] and $record["extra"]["foo"] will be rendered as part of the final result. +> It is also capable to interpolate values from the log record, into the output format template used by the formatter to generate the final result, and in order to do it, you need to provide the log record values you are interested in, in the output template string using the form %value%, e.g: "'%context.foo% => %extra.foo%'" , in this example the values $record->context["foo"] and $record->extra["foo"] will be rendered as part of th final result. In the following example, we demonstrate how to: 1. Create a `LineFormatter` instance and set a custom output format template. diff --git a/doc/04-extending.md b/doc/04-extending.md index c7075c76..0a2ad338 100644 --- a/doc/04-extending.md +++ b/doc/04-extending.md @@ -43,10 +43,10 @@ class PDOHandler extends AbstractProcessingHandler } $this->statement->execute(array( - 'channel' => $record['channel'], - 'level' => $record['level'], - 'message' => $record['formatted'], - 'time' => $record['datetime']->format('U'), + 'channel' => $record->channel, + 'level' => $record->level, + 'message' => $record->formatted, + 'time' => $record->datetime->format('U'), )); } @@ -78,6 +78,6 @@ $logger->info('My logger is now ready'); The `Monolog\Handler\AbstractProcessingHandler` class provides most of the logic needed for the handler, including the use of processors and the formatting -of the record (which is why we use ``$record['formatted']`` instead of ``$record['message']``). +of the record (which is why we use ``$record->formatted`` instead of ``$record->message``). ← [Utility classes](03-utilities.md) diff --git a/src/Monolog/Formatter/ChromePHPFormatter.php b/src/Monolog/Formatter/ChromePHPFormatter.php index b588e316..e855d64a 100644 --- a/src/Monolog/Formatter/ChromePHPFormatter.php +++ b/src/Monolog/Formatter/ChromePHPFormatter.php @@ -44,27 +44,27 @@ class ChromePHPFormatter implements FormatterInterface { // Retrieve the line and file if set and remove them from the formatted extra $backtrace = 'unknown'; - if (isset($record['extra']['file'], $record['extra']['line'])) { - $backtrace = $record['extra']['file'].' : '.$record['extra']['line']; - unset($record['extra']['file'], $record['extra']['line']); + if (isset($record->extra['file'], $record->extra['line'])) { + $backtrace = $record->extra['file'].' : '.$record->extra['line']; + unset($record->extra['file'], $record->extra['line']); } - $message = ['message' => $record['message']]; - if ($record['context']) { - $message['context'] = $record['context']; + $message = ['message' => $record->message]; + if ($record->context) { + $message['context'] = $record->context; } - if ($record['extra']) { - $message['extra'] = $record['extra']; + if ($record->extra) { + $message['extra'] = $record->extra; } if (count($message) === 1) { $message = reset($message); } return [ - $record['channel'], + $record->channel, $message, $backtrace, - $this->logLevels[$record['level']], + $this->logLevels[$record->level], ]; } diff --git a/src/Monolog/Formatter/FlowdockFormatter.php b/src/Monolog/Formatter/FlowdockFormatter.php index 1b932a2b..6518976e 100644 --- a/src/Monolog/Formatter/FlowdockFormatter.php +++ b/src/Monolog/Formatter/FlowdockFormatter.php @@ -45,26 +45,26 @@ class FlowdockFormatter implements FormatterInterface { $tags = [ '#logs', - '#' . strtolower($record['level_name']), - '#' . $record['channel'], + '#' . strtolower($record->levelName), + '#' . $record->channel, ]; - foreach ($record['extra'] as $value) { + foreach ($record->extra as $value) { $tags[] = '#' . $value; } $subject = sprintf( 'in %s: %s - %s', $this->source, - $record['level_name'], - $this->getShortMessage($record['message']) + $record->levelName, + $this->getShortMessage($record->message) ); return [ 'source' => $this->source, 'from_address' => $this->sourceEmail, 'subject' => $subject, - 'content' => $record['message'], + 'content' => $record->message, 'tags' => $tags, 'project' => $this->source, ]; diff --git a/src/Monolog/Formatter/FluentdFormatter.php b/src/Monolog/Formatter/FluentdFormatter.php index 2b76e751..31d4d5e2 100644 --- a/src/Monolog/Formatter/FluentdFormatter.php +++ b/src/Monolog/Formatter/FluentdFormatter.php @@ -58,23 +58,23 @@ class FluentdFormatter implements FormatterInterface public function format(LogRecord $record): string { - $tag = $record['channel']; + $tag = $record->channel; if ($this->levelTag) { - $tag .= '.' . strtolower($record['level_name']); + $tag .= '.' . strtolower($record->levelName); } $message = [ - 'message' => $record['message'], - 'context' => $record['context'], - 'extra' => $record['extra'], + 'message' => $record->message, + 'context' => $record->context, + 'extra' => $record->extra, ]; if (!$this->levelTag) { - $message['level'] = $record['level']; - $message['level_name'] = $record['level_name']; + $message['level'] = $record->level; + $message['level_name'] = $record->levelName; } - return Utils::jsonEncode([$tag, $record['datetime']->getTimestamp(), $message]); + return Utils::jsonEncode([$tag, $record->datetime->getTimestamp(), $message]); } public function formatBatch(array $records): string diff --git a/src/Monolog/Formatter/GelfMessageFormatter.php b/src/Monolog/Formatter/GelfMessageFormatter.php index ac8eb9db..bf24b372 100644 --- a/src/Monolog/Formatter/GelfMessageFormatter.php +++ b/src/Monolog/Formatter/GelfMessageFormatter.php @@ -87,31 +87,31 @@ class GelfMessageFormatter extends NormalizerFormatter public function format(LogRecord $record): Message { $context = $extra = []; - if (isset($record['context'])) { + if (isset($record->context)) { /** @var mixed[] $context */ - $context = parent::normalize($record['context']); + $context = parent::normalize($record->context); } - if (isset($record['extra'])) { + if (isset($record->extra)) { /** @var mixed[] $extra */ - $extra = parent::normalize($record['extra']); + $extra = parent::normalize($record->extra); } $message = new Message(); $message - ->setTimestamp($record['datetime']) - ->setShortMessage((string) $record['message']) + ->setTimestamp($record->datetime) + ->setShortMessage((string) $record->message) ->setHost($this->systemName) - ->setLevel($this->logLevels[$record['level']]); + ->setLevel($this->logLevels[$record->level]); // message length + system name length + 200 for padding / metadata - $len = 200 + strlen((string) $record['message']) + strlen($this->systemName); + $len = 200 + strlen((string) $record->message) + strlen($this->systemName); if ($len > $this->maxLength) { - $message->setShortMessage(Utils::substr($record['message'], 0, $this->maxLength)); + $message->setShortMessage(Utils::substr($record->message, 0, $this->maxLength)); } - if (isset($record['channel'])) { - $message->setFacility($record['channel']); + if (isset($record->channel)) { + $message->setFacility($record->channel); } if (isset($extra['line'])) { $message->setLine($extra['line']); diff --git a/src/Monolog/Formatter/HtmlFormatter.php b/src/Monolog/Formatter/HtmlFormatter.php index fb2fb9f6..d534755e 100644 --- a/src/Monolog/Formatter/HtmlFormatter.php +++ b/src/Monolog/Formatter/HtmlFormatter.php @@ -86,23 +86,23 @@ class HtmlFormatter extends NormalizerFormatter */ public function format(LogRecord $record): string { - $output = $this->addTitle($record['level_name'], $record['level']); + $output = $this->addTitle($record->levelName, $record->level); $output .= ''; - $output .= $this->addRow('Message', (string) $record['message']); - $output .= $this->addRow('Time', $this->formatDate($record['datetime'])); - $output .= $this->addRow('Channel', $record['channel']); - if ($record['context']) { + $output .= $this->addRow('Message', (string) $record->message); + $output .= $this->addRow('Time', $this->formatDate($record->datetime)); + $output .= $this->addRow('Channel', $record->channel); + if ($record->context) { $embeddedTable = '
'; - foreach ($record['context'] as $key => $value) { + foreach ($record->context as $key => $value) { $embeddedTable .= $this->addRow((string) $key, $this->convertToString($value)); } $embeddedTable .= '
'; $output .= $this->addRow('Context', $embeddedTable, false); } - if ($record['extra']) { + if ($record->extra) { $embeddedTable = ''; - foreach ($record['extra'] as $key => $value) { + foreach ($record->extra as $key => $value) { $embeddedTable .= $this->addRow((string) $key, $this->convertToString($value)); } $embeddedTable .= '
'; diff --git a/src/Monolog/Formatter/JsonFormatter.php b/src/Monolog/Formatter/JsonFormatter.php index a44aa89d..aee6b5df 100644 --- a/src/Monolog/Formatter/JsonFormatter.php +++ b/src/Monolog/Formatter/JsonFormatter.php @@ -20,8 +20,6 @@ use Monolog\LogRecord; * This can be useful to log to databases or remote APIs * * @author Jordi Boggiano - * - * @phpstan-import-type Record from \Monolog\Logger */ class JsonFormatter extends NormalizerFormatter { @@ -29,13 +27,13 @@ class JsonFormatter extends NormalizerFormatter public const BATCH_MODE_NEWLINES = 2; /** @var self::BATCH_MODE_* */ - protected $batchMode; - /** @var bool */ - protected $appendNewline; - /** @var bool */ - protected $ignoreEmptyContextAndExtra; - /** @var bool */ - protected $includeStacktraces = false; + protected int $batchMode; + + protected bool $appendNewline; + + protected bool $ignoreEmptyContextAndExtra; + + protected bool $includeStacktraces = false; /** * @param self::BATCH_MODE_* $batchMode @@ -123,7 +121,7 @@ class JsonFormatter extends NormalizerFormatter /** * Return a JSON-encoded array of records. * - * @phpstan-param Record[] $records + * @phpstan-param LogRecord[] $records */ protected function formatBatchJson(array $records): string { @@ -134,7 +132,7 @@ class JsonFormatter extends NormalizerFormatter * Use new lines to separate records instead of a * JSON-encoded array. * - * @phpstan-param Record[] $records + * @phpstan-param LogRecord[] $records */ protected function formatBatchNewlines(array $records): string { diff --git a/src/Monolog/Formatter/LogstashFormatter.php b/src/Monolog/Formatter/LogstashFormatter.php index 4e9faddc..b7b96cb4 100644 --- a/src/Monolog/Formatter/LogstashFormatter.php +++ b/src/Monolog/Formatter/LogstashFormatter.php @@ -65,37 +65,37 @@ class LogstashFormatter extends NormalizerFormatter */ public function format(LogRecord $record): string { - $record = parent::format($record); + $recordData = parent::format($record); - if (empty($record['datetime'])) { - $record['datetime'] = gmdate('c'); + if (empty($recordData['datetime'])) { + $recordData['datetime'] = gmdate('c'); } $message = [ - '@timestamp' => $record['datetime'], + '@timestamp' => $recordData['datetime'], '@version' => 1, 'host' => $this->systemName, ]; - if (isset($record['message'])) { - $message['message'] = $record['message']; + if (isset($recordData['message'])) { + $message['message'] = $recordData['message']; } - if (isset($record['channel'])) { - $message['type'] = $record['channel']; - $message['channel'] = $record['channel']; + if (isset($recordData['channel'])) { + $message['type'] = $recordData['channel']; + $message['channel'] = $recordData['channel']; } - if (isset($record['level_name'])) { - $message['level'] = $record['level_name']; + if (isset($recordData['level_name'])) { + $message['level'] = $recordData['level_name']; } - if (isset($record['level'])) { - $message['monolog_level'] = $record['level']; + if (isset($recordData['level'])) { + $message['monolog_level'] = $recordData['level']; } if ($this->applicationName) { $message['type'] = $this->applicationName; } - if (!empty($record['extra'])) { - $message[$this->extraKey] = $record['extra']; + if (!empty($recordData['extra'])) { + $message[$this->extraKey] = $recordData['extra']; } - if (!empty($record['context'])) { - $message[$this->contextKey] = $record['context']; + if (!empty($recordData['context'])) { + $message[$this->contextKey] = $recordData['context']; } return $this->toJson($message) . "\n"; diff --git a/src/Monolog/Formatter/MongoDBFormatter.php b/src/Monolog/Formatter/MongoDBFormatter.php index aa34e520..f7207241 100644 --- a/src/Monolog/Formatter/MongoDBFormatter.php +++ b/src/Monolog/Formatter/MongoDBFormatter.php @@ -31,7 +31,7 @@ class MongoDBFormatter implements FormatterInterface private $isLegacyMongoExt; /** - * @param int $maxNestingLevel 0 means infinite nesting, the $record itself is level 1, $record['context'] is 2 + * @param int $maxNestingLevel 0 means infinite nesting, the $record itself is level 1, $record->context is 2 * @param bool $exceptionTraceAsString set to false to log exception traces as a sub documents instead of strings */ public function __construct(int $maxNestingLevel = 3, bool $exceptionTraceAsString = true) diff --git a/src/Monolog/Formatter/WildfireFormatter.php b/src/Monolog/Formatter/WildfireFormatter.php index f686781f..7170b020 100644 --- a/src/Monolog/Formatter/WildfireFormatter.php +++ b/src/Monolog/Formatter/WildfireFormatter.php @@ -61,38 +61,38 @@ class WildfireFormatter extends NormalizerFormatter { // Retrieve the line and file if set and remove them from the formatted extra $file = $line = ''; - if (isset($record['extra']['file'])) { - $file = $record['extra']['file']; - unset($record['extra']['file']); + if (isset($record->extra['file'])) { + $file = $record->extra['file']; + unset($record->extra['file']); } - if (isset($record['extra']['line'])) { - $line = $record['extra']['line']; - unset($record['extra']['line']); + if (isset($record->extra['line'])) { + $line = $record->extra['line']; + unset($record->extra['line']); } /** @var mixed[] $record */ $record = $this->normalize($record); - $message = ['message' => $record['message']]; + $message = ['message' => $record->message]; $handleError = false; - if ($record['context']) { - $message['context'] = $record['context']; + if ($record->context) { + $message['context'] = $record->context; $handleError = true; } - if ($record['extra']) { - $message['extra'] = $record['extra']; + if ($record->extra) { + $message['extra'] = $record->extra; $handleError = true; } if (count($message) === 1) { $message = reset($message); } - if (isset($record['context']['table'])) { + if (isset($record->context['table'])) { $type = 'TABLE'; - $label = $record['channel'] .': '. $record['message']; - $message = $record['context']['table']; + $label = $record->channel .': '. $record->message; + $message = $record->context['table']; } else { - $type = $this->logLevels[$record['level']]; - $label = $record['channel']; + $type = $this->logLevels[$record->level]; + $label = $record->channel; } // Create JSON object describing the appearance of the message in the console diff --git a/src/Monolog/Handler/AbstractHandler.php b/src/Monolog/Handler/AbstractHandler.php index 07c0d3e9..51f3db53 100644 --- a/src/Monolog/Handler/AbstractHandler.php +++ b/src/Monolog/Handler/AbstractHandler.php @@ -51,7 +51,7 @@ abstract class AbstractHandler extends Handler implements ResettableInterface */ public function isHandling(LogRecord $record): bool { - return $record['level'] >= $this->level; + return $record->level >= $this->level; } /** diff --git a/src/Monolog/Handler/AbstractProcessingHandler.php b/src/Monolog/Handler/AbstractProcessingHandler.php index bed34c12..25320053 100644 --- a/src/Monolog/Handler/AbstractProcessingHandler.php +++ b/src/Monolog/Handler/AbstractProcessingHandler.php @@ -23,8 +23,6 @@ use Monolog\LogRecord; * * @phpstan-import-type LevelName from \Monolog\Logger * @phpstan-import-type Level from \Monolog\Logger - * @phpstan-import-type Record from \Monolog\Logger - * @phpstan-type FormattedRecord array{message: string, context: mixed[], level: Level, level_name: LevelName, channel: string, datetime: \DateTimeImmutable, extra: mixed[], formatted: mixed} */ abstract class AbstractProcessingHandler extends AbstractHandler implements ProcessableHandlerInterface, FormattableHandlerInterface { @@ -44,7 +42,7 @@ abstract class AbstractProcessingHandler extends AbstractHandler implements Proc $record = $this->processRecord($record); } - $record['formatted'] = $this->getFormatter()->format($record); + $record->formatted = $this->getFormatter()->format($record); $this->write($record); @@ -52,9 +50,7 @@ abstract class AbstractProcessingHandler extends AbstractHandler implements Proc } /** - * Writes the record down to the log of the implementing handler - * - * @phpstan-param FormattedRecord $record + * Writes the (already formatted) record down to the log of the implementing handler */ abstract protected function write(LogRecord $record): void; diff --git a/src/Monolog/Handler/AmqpHandler.php b/src/Monolog/Handler/AmqpHandler.php index da84f809..09c5b3d8 100644 --- a/src/Monolog/Handler/AmqpHandler.php +++ b/src/Monolog/Handler/AmqpHandler.php @@ -19,9 +19,6 @@ use PhpAmqpLib\Channel\AMQPChannel; use AMQPExchange; use Monolog\LogRecord; -/** - * @phpstan-import-type Record from \Monolog\Logger - */ class AmqpHandler extends AbstractProcessingHandler { /** @@ -57,7 +54,7 @@ class AmqpHandler extends AbstractProcessingHandler */ protected function write(LogRecord $record): void { - $data = $record["formatted"]; + $data = $record->formatted; $routingKey = $this->getRoutingKey($record); if ($this->exchange instanceof AMQPExchange) { @@ -95,7 +92,6 @@ class AmqpHandler extends AbstractProcessingHandler continue; } - /** @var Record $record */ $record = $this->processRecord($record); $data = $this->getFormatter()->format($record); @@ -111,12 +107,10 @@ class AmqpHandler extends AbstractProcessingHandler /** * Gets the routing key for the AMQP exchange - * - * @phpstan-param Record $record */ protected function getRoutingKey(LogRecord $record): string { - $routingKey = sprintf('%s.%s', $record['level_name'], $record['channel']); + $routingKey = sprintf('%s.%s', $record->levelName, $record->channel); return strtolower($routingKey); } diff --git a/src/Monolog/Handler/BrowserConsoleHandler.php b/src/Monolog/Handler/BrowserConsoleHandler.php index 471778aa..fa66da4b 100644 --- a/src/Monolog/Handler/BrowserConsoleHandler.php +++ b/src/Monolog/Handler/BrowserConsoleHandler.php @@ -27,15 +27,13 @@ use const E_USER_DEPRECATED; * Handler sending logs to browser's javascript console with no browser extension required * * @author Olivier Poitrey - * - * @phpstan-import-type FormattedRecord from AbstractProcessingHandler */ class BrowserConsoleHandler extends AbstractProcessingHandler { - /** @var bool */ - protected static $initialized = false; - /** @var FormattedRecord[] */ - protected static $records = []; + protected static bool $initialized = false; + + /** @var LogRecord[] */ + protected static array $records = []; protected const FORMAT_HTML = 'html'; protected const FORMAT_JS = 'js'; @@ -174,18 +172,18 @@ class BrowserConsoleHandler extends AbstractProcessingHandler { $script = []; foreach (static::$records as $record) { - $context = static::dump('Context', $record['context']); - $extra = static::dump('Extra', $record['extra']); + $context = self::dump('Context', $record->context); + $extra = self::dump('Extra', $record->extra); if (empty($context) && empty($extra)) { - $script[] = static::call_array('log', static::handleStyles($record['formatted'])); + $script[] = self::call_array('log', self::handleStyles($record->formatted)); } else { $script = array_merge( $script, - [static::call_array('groupCollapsed', static::handleStyles($record['formatted']))], + [self::call_array('groupCollapsed', self::handleStyles($record->formatted))], $context, $extra, - [static::call('groupEnd')] + [self::call('groupEnd')] ); } } @@ -204,14 +202,14 @@ class BrowserConsoleHandler extends AbstractProcessingHandler foreach (array_reverse($matches) as $match) { $args[] = '"font-weight: normal"'; - $args[] = static::quote(static::handleCustomStyles($match[2][0], $match[1][0])); + $args[] = self::quote(static::handleCustomStyles($match[2][0], $match[1][0])); $pos = $match[0][1]; $format = Utils::substr($format, 0, $pos) . '%c' . $match[1][0] . '%c' . Utils::substr($format, $pos + strlen($match[0][0])); } - $args[] = static::quote('font-weight: normal'); - $args[] = static::quote($format); + $args[] = self::quote('font-weight: normal'); + $args[] = self::quote($format); return array_reverse($args); } @@ -254,13 +252,13 @@ class BrowserConsoleHandler extends AbstractProcessingHandler if (empty($dict)) { return $script; } - $script[] = static::call('log', static::quote('%c%s'), static::quote('font-weight: bold'), static::quote($title)); + $script[] = self::call('log', self::quote('%c%s'), self::quote('font-weight: bold'), self::quote($title)); foreach ($dict as $key => $value) { $value = json_encode($value); if (empty($value)) { - $value = static::quote(''); + $value = self::quote(''); } - $script[] = static::call('log', static::quote('%s: %o'), static::quote((string) $key), $value); + $script[] = self::call('log', self::quote('%s: %o'), self::quote((string) $key), $value); } return $script; @@ -281,7 +279,7 @@ class BrowserConsoleHandler extends AbstractProcessingHandler throw new \UnexpectedValueException('Expected the first arg to be a string, got: '.var_export($method, true)); } - return static::call_array($method, $args); + return self::call_array($method, $args); } /** diff --git a/src/Monolog/Handler/BufferHandler.php b/src/Monolog/Handler/BufferHandler.php index 6035415f..8edf6965 100644 --- a/src/Monolog/Handler/BufferHandler.php +++ b/src/Monolog/Handler/BufferHandler.php @@ -23,25 +23,23 @@ use Monolog\LogRecord; * sending one per log message. * * @author Christophe Coevoet - * - * @phpstan-import-type Record from \Monolog\Logger */ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterface, FormattableHandlerInterface { use ProcessableHandlerTrait; - /** @var HandlerInterface */ - protected $handler; - /** @var int */ - protected $bufferSize = 0; - /** @var int */ - protected $bufferLimit; - /** @var bool */ - protected $flushOnOverflow; - /** @var Record[] */ - protected $buffer = []; - /** @var bool */ - protected $initialized = false; + protected HandlerInterface $handler; + + protected int $bufferSize = 0; + + protected int $bufferLimit; + + protected bool $flushOnOverflow; + + /** @var LogRecord[] */ + protected array $buffer = []; + + protected bool $initialized = false; /** * @param HandlerInterface $handler Handler. @@ -61,7 +59,7 @@ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterfa */ public function handle(LogRecord $record): bool { - if ($record['level'] < $this->level) { + if ($record->level < $this->level) { return false; } @@ -81,7 +79,6 @@ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterfa } if ($this->processors) { - /** @var Record $record */ $record = $this->processRecord($record); } diff --git a/src/Monolog/Handler/ChromePHPHandler.php b/src/Monolog/Handler/ChromePHPHandler.php index f8e9f237..345ba90c 100644 --- a/src/Monolog/Handler/ChromePHPHandler.php +++ b/src/Monolog/Handler/ChromePHPHandler.php @@ -24,8 +24,6 @@ use Monolog\DateTimeImmutable; * This also works out of the box with Firefox 43+ * * @author Christophe Coevoet - * - * @phpstan-import-type Record from \Monolog\Logger */ class ChromePHPHandler extends AbstractProcessingHandler { @@ -88,10 +86,10 @@ class ChromePHPHandler extends AbstractProcessingHandler $messages = []; foreach ($records as $record) { - if ($record['level'] < $this->level) { + if ($record->level < $this->level) { continue; } - /** @var Record $message */ + $message = $this->processRecord($record); $messages[] = $message; } @@ -123,7 +121,7 @@ class ChromePHPHandler extends AbstractProcessingHandler return; } - self::$json['rows'][] = $record['formatted']; + self::$json['rows'][] = $record->formatted; $this->send(); } diff --git a/src/Monolog/Handler/CouchDBHandler.php b/src/Monolog/Handler/CouchDBHandler.php index 96bd1699..abdce0b5 100644 --- a/src/Monolog/Handler/CouchDBHandler.php +++ b/src/Monolog/Handler/CouchDBHandler.php @@ -56,7 +56,7 @@ class CouchDBHandler extends AbstractProcessingHandler $context = stream_context_create([ 'http' => [ 'method' => 'POST', - 'content' => $record['formatted'], + 'content' => $record->formatted, 'ignore_errors' => true, 'max_redirects' => 0, 'header' => 'Content-type: application/json', diff --git a/src/Monolog/Handler/CubeHandler.php b/src/Monolog/Handler/CubeHandler.php index 5ea634d5..b86d50af 100644 --- a/src/Monolog/Handler/CubeHandler.php +++ b/src/Monolog/Handler/CubeHandler.php @@ -115,20 +115,20 @@ class CubeHandler extends AbstractProcessingHandler */ protected function write(LogRecord $record): void { - $date = $record['datetime']; + $date = $record->datetime; $data = ['time' => $date->format('Y-m-d\TH:i:s.uO')]; - unset($record['datetime']); + unset($record->datetime); - if (isset($record['context']['type'])) { - $data['type'] = $record['context']['type']; - unset($record['context']['type']); + if (isset($record->context['type'])) { + $data['type'] = $record->context['type']; + unset($record->context['type']); } else { - $data['type'] = $record['channel']; + $data['type'] = $record->channel; } - $data['data'] = $record['context']; - $data['data']['level'] = $record['level']; + $data['data'] = $record->context; + $data['data']['level'] = $record->level; if ($this->scheme === 'http') { $this->writeHttp(Utils::jsonEncode($data)); diff --git a/src/Monolog/Handler/Curl/Util.php b/src/Monolog/Handler/Curl/Util.php index 7213e8ee..73a7660b 100644 --- a/src/Monolog/Handler/Curl/Util.php +++ b/src/Monolog/Handler/Curl/Util.php @@ -34,7 +34,7 @@ final class Util /** * Executes a CURL request with optional retries and exception on failure * - * @param resource|CurlHandle $ch curl handler + * @param CurlHandle $ch curl handler * @param int $retries * @param bool $closeAfterDone * @return bool|string @see curl_exec diff --git a/src/Monolog/Handler/DeduplicationHandler.php b/src/Monolog/Handler/DeduplicationHandler.php index 776e293b..f9d80f2d 100644 --- a/src/Monolog/Handler/DeduplicationHandler.php +++ b/src/Monolog/Handler/DeduplicationHandler.php @@ -34,8 +34,6 @@ use Monolog\LogRecord; * same way. * * @author Jordi Boggiano - * - * @phpstan-import-type Record from \Monolog\Logger * @phpstan-import-type LevelName from \Monolog\Logger * @phpstan-import-type Level from \Monolog\Logger */ @@ -88,7 +86,7 @@ class DeduplicationHandler extends BufferHandler $passthru = null; foreach ($this->buffer as $record) { - if ($record['level'] >= $this->deduplicationLevel) { + if ($record->level >= $this->deduplicationLevel) { $passthru = $passthru || !$this->isDuplicate($record); if ($passthru) { $this->appendRecord($record); @@ -108,9 +106,6 @@ class DeduplicationHandler extends BufferHandler } } - /** - * @phpstan-param Record $record - */ private function isDuplicate(LogRecord $record): bool { if (!file_exists($this->deduplicationStore)) { @@ -123,13 +118,13 @@ class DeduplicationHandler extends BufferHandler } $yesterday = time() - 86400; - $timestampValidity = $record['datetime']->getTimestamp() - $this->time; - $expectedMessage = preg_replace('{[\r\n].*}', '', $record['message']); + $timestampValidity = $record->datetime->getTimestamp() - $this->time; + $expectedMessage = preg_replace('{[\r\n].*}', '', $record->message); for ($i = count($store) - 1; $i >= 0; $i--) { list($timestamp, $level, $message) = explode(':', $store[$i], 3); - if ($level === $record['level_name'] && $message === $expectedMessage && $timestamp > $timestampValidity) { + if ($level === $record->levelName && $message === $expectedMessage && $timestamp > $timestampValidity) { return true; } @@ -177,11 +172,8 @@ class DeduplicationHandler extends BufferHandler $this->gc = false; } - /** - * @phpstan-param Record $record - */ private function appendRecord(LogRecord $record): void { - file_put_contents($this->deduplicationStore, $record['datetime']->getTimestamp() . ':' . $record['level_name'] . ':' . preg_replace('{[\r\n].*}', '', $record['message']) . "\n", FILE_APPEND); + file_put_contents($this->deduplicationStore, $record->datetime->getTimestamp() . ':' . $record->levelName . ':' . preg_replace('{[\r\n].*}', '', $record->message) . "\n", FILE_APPEND); } } diff --git a/src/Monolog/Handler/DoctrineCouchDBHandler.php b/src/Monolog/Handler/DoctrineCouchDBHandler.php index f2c34c87..9b3426f8 100644 --- a/src/Monolog/Handler/DoctrineCouchDBHandler.php +++ b/src/Monolog/Handler/DoctrineCouchDBHandler.php @@ -38,7 +38,7 @@ class DoctrineCouchDBHandler extends AbstractProcessingHandler */ protected function write(LogRecord $record): void { - $this->client->postDocument($record['formatted']); + $this->client->postDocument($record->formatted); } protected function getDefaultFormatter(): FormatterInterface diff --git a/src/Monolog/Handler/DynamoDbHandler.php b/src/Monolog/Handler/DynamoDbHandler.php index f3b8571f..b154d143 100644 --- a/src/Monolog/Handler/DynamoDbHandler.php +++ b/src/Monolog/Handler/DynamoDbHandler.php @@ -70,7 +70,7 @@ class DynamoDbHandler extends AbstractProcessingHandler */ protected function write(LogRecord $record): void { - $filtered = $this->filterEmptyFields($record['formatted']); + $filtered = $this->filterEmptyFields($record->formatted); if ($this->version === 3) { $formatted = $this->marshaler->marshalItem($filtered); } else { diff --git a/src/Monolog/Handler/ElasticaHandler.php b/src/Monolog/Handler/ElasticaHandler.php index 8caf2c0a..838d9d2b 100644 --- a/src/Monolog/Handler/ElasticaHandler.php +++ b/src/Monolog/Handler/ElasticaHandler.php @@ -70,7 +70,7 @@ class ElasticaHandler extends AbstractProcessingHandler */ protected function write(LogRecord $record): void { - $this->bulkSend([$record['formatted']]); + $this->bulkSend([$record->formatted]); } /** diff --git a/src/Monolog/Handler/ElasticsearchHandler.php b/src/Monolog/Handler/ElasticsearchHandler.php index a62fc279..0694bcb0 100644 --- a/src/Monolog/Handler/ElasticsearchHandler.php +++ b/src/Monolog/Handler/ElasticsearchHandler.php @@ -77,7 +77,7 @@ class ElasticsearchHandler extends AbstractProcessingHandler */ protected function write(LogRecord $record): void { - $this->bulkSend([$record['formatted']]); + $this->bulkSend([$record->formatted]); } /** @@ -122,7 +122,7 @@ class ElasticsearchHandler extends AbstractProcessingHandler /** * Use Elasticsearch bulk API to send list of documents * - * @param array[] $records Records + _index/_type keys + * @param array> $records Records + _index/_type keys * @throws \RuntimeException */ protected function bulkSend(array $records): void diff --git a/src/Monolog/Handler/ErrorLogHandler.php b/src/Monolog/Handler/ErrorLogHandler.php index 2815f5e3..c0f62298 100644 --- a/src/Monolog/Handler/ErrorLogHandler.php +++ b/src/Monolog/Handler/ErrorLogHandler.php @@ -75,12 +75,12 @@ class ErrorLogHandler extends AbstractProcessingHandler protected function write(LogRecord $record): void { if (!$this->expandNewlines) { - error_log((string) $record['formatted'], $this->messageType); + error_log((string) $record->formatted, $this->messageType); return; } - $lines = preg_split('{[\r\n]+}', (string) $record['formatted']); + $lines = preg_split('{[\r\n]+}', (string) $record->formatted); if ($lines === false) { $pcreErrorCode = preg_last_error(); throw new \RuntimeException('Failed to preg_split formatted string: ' . $pcreErrorCode . ' / '. Utils::pcreLastErrorMessage($pcreErrorCode)); diff --git a/src/Monolog/Handler/FallbackGroupHandler.php b/src/Monolog/Handler/FallbackGroupHandler.php index 1e5b623b..ac6e9042 100644 --- a/src/Monolog/Handler/FallbackGroupHandler.php +++ b/src/Monolog/Handler/FallbackGroupHandler.php @@ -20,8 +20,6 @@ use Monolog\LogRecord; * If a handler fails, the exception is suppressed and the record is forwarded to the next handler. * * As soon as one handler handles a record successfully, the handling stops there. - * - * @phpstan-import-type Record from \Monolog\Logger */ class FallbackGroupHandler extends GroupHandler { @@ -31,7 +29,6 @@ class FallbackGroupHandler extends GroupHandler public function handle(LogRecord $record): bool { if ($this->processors) { - /** @var Record $record */ $record = $this->processRecord($record); } foreach ($this->handlers as $handler) { @@ -56,7 +53,6 @@ class FallbackGroupHandler extends GroupHandler foreach ($records as $record) { $processed[] = $this->processRecord($record); } - /** @var Record[] $records */ $records = $processed; } diff --git a/src/Monolog/Handler/FilterHandler.php b/src/Monolog/Handler/FilterHandler.php index c430b355..d6703fe1 100644 --- a/src/Monolog/Handler/FilterHandler.php +++ b/src/Monolog/Handler/FilterHandler.php @@ -24,8 +24,6 @@ use Monolog\LogRecord; * * @author Hennadiy Verkh * @author Jordi Boggiano - * - * @phpstan-import-type Record from \Monolog\Logger * @phpstan-import-type Level from \Monolog\Logger * @phpstan-import-type LevelName from \Monolog\Logger */ @@ -37,7 +35,7 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese * Handler or factory callable($record, $this) * * @var callable|HandlerInterface - * @phpstan-var callable(?Record, HandlerInterface): HandlerInterface|HandlerInterface + * @phpstan-var (callable(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface */ protected $handler; @@ -57,7 +55,7 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese protected $bubble; /** - * @psalm-param HandlerInterface|callable(?Record, HandlerInterface): HandlerInterface $handler + * @phpstan-param (callable(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface $handler * * @param callable|HandlerInterface $handler Handler or factory callable($record|null, $filterHandler). * @param int|array $minLevelOrList A list of levels to accept or a minimum level if maxLevel is provided @@ -114,7 +112,7 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese */ public function isHandling(LogRecord $record): bool { - return isset($this->acceptedLevels[$record['level']]); + return isset($this->acceptedLevels[$record->level]); } /** @@ -127,7 +125,6 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese } if ($this->processors) { - /** @var Record $record */ $record = $this->processRecord($record); } @@ -159,8 +156,6 @@ class FilterHandler extends Handler implements ProcessableHandlerInterface, Rese * If the handler was provided as a factory callable, this will trigger the handler's instantiation. * * @return HandlerInterface - * - * @phpstan-param Record $record */ public function getHandler(LogRecord $record = null) { diff --git a/src/Monolog/Handler/FingersCrossed/ActivationStrategyInterface.php b/src/Monolog/Handler/FingersCrossed/ActivationStrategyInterface.php index f1077279..e8a1b0b0 100644 --- a/src/Monolog/Handler/FingersCrossed/ActivationStrategyInterface.php +++ b/src/Monolog/Handler/FingersCrossed/ActivationStrategyInterface.php @@ -17,15 +17,11 @@ use Monolog\LogRecord; * Interface for activation strategies for the FingersCrossedHandler. * * @author Johannes M. Schmitt - * - * @phpstan-import-type Record from \Monolog\Logger */ interface ActivationStrategyInterface { /** * Returns whether the given record activates the handler. - * - * @phpstan-param Record $record */ public function isHandlerActivated(LogRecord $record): bool; } diff --git a/src/Monolog/Handler/FingersCrossed/ChannelLevelActivationStrategy.php b/src/Monolog/Handler/FingersCrossed/ChannelLevelActivationStrategy.php index fd2b22c6..ca34b3b7 100644 --- a/src/Monolog/Handler/FingersCrossed/ChannelLevelActivationStrategy.php +++ b/src/Monolog/Handler/FingersCrossed/ChannelLevelActivationStrategy.php @@ -34,8 +34,6 @@ use Monolog\LogRecord; * * * @author Mike Meessen - * - * @phpstan-import-type Record from \Monolog\Logger * @phpstan-import-type Level from \Monolog\Logger * @phpstan-import-type LevelName from \Monolog\Logger */ @@ -64,15 +62,12 @@ class ChannelLevelActivationStrategy implements ActivationStrategyInterface $this->channelToActionLevel = array_map('Monolog\Logger::toMonologLevel', $channelToActionLevel); } - /** - * @phpstan-param Record $record - */ public function isHandlerActivated(LogRecord $record): bool { - if (isset($this->channelToActionLevel[$record['channel']])) { - return $record['level'] >= $this->channelToActionLevel[$record['channel']]; + if (isset($this->channelToActionLevel[$record->channel])) { + return $record->level >= $this->channelToActionLevel[$record->channel]; } - return $record['level'] >= $this->defaultActionLevel; + return $record->level >= $this->defaultActionLevel; } } diff --git a/src/Monolog/Handler/FingersCrossed/ErrorLevelActivationStrategy.php b/src/Monolog/Handler/FingersCrossed/ErrorLevelActivationStrategy.php index 0131e44f..ba98f505 100644 --- a/src/Monolog/Handler/FingersCrossed/ErrorLevelActivationStrategy.php +++ b/src/Monolog/Handler/FingersCrossed/ErrorLevelActivationStrategy.php @@ -42,6 +42,6 @@ class ErrorLevelActivationStrategy implements ActivationStrategyInterface public function isHandlerActivated(LogRecord $record): bool { - return $record['level'] >= $this->actionLevel; + return $record->level >= $this->actionLevel; } } diff --git a/src/Monolog/Handler/FingersCrossedHandler.php b/src/Monolog/Handler/FingersCrossedHandler.php index 4bcb23c7..872b9a18 100644 --- a/src/Monolog/Handler/FingersCrossedHandler.php +++ b/src/Monolog/Handler/FingersCrossedHandler.php @@ -34,8 +34,6 @@ use Monolog\LogRecord; * Monolog\Handler\FingersCrossed\ namespace. * * @author Jordi Boggiano - * - * @phpstan-import-type Record from \Monolog\Logger * @phpstan-import-type Level from \Monolog\Logger * @phpstan-import-type LevelName from \Monolog\Logger */ @@ -45,7 +43,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa /** * @var callable|HandlerInterface - * @phpstan-var callable(?Record, HandlerInterface): HandlerInterface|HandlerInterface + * @phpstan-var (callable(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface */ protected $handler; /** @var ActivationStrategyInterface */ @@ -54,7 +52,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa protected $buffering = true; /** @var int */ protected $bufferSize; - /** @var Record[] */ + /** @var LogRecord[] */ protected $buffer = []; /** @var bool */ protected $stopBuffering; @@ -67,7 +65,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa protected $bubble; /** - * @psalm-param HandlerInterface|callable(?Record, HandlerInterface): HandlerInterface $handler + * @phpstan-param (callable(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface $handler * * @param callable|HandlerInterface $handler Handler or factory callable($record|null, $fingersCrossedHandler). * @param int|string|ActivationStrategyInterface $activationStrategy Strategy which determines when this handler takes action, or a level name/value at which the handler is activated @@ -132,7 +130,6 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa public function handle(LogRecord $record): bool { if ($this->processors) { - /** @var Record $record */ $record = $this->processRecord($record); } @@ -191,7 +188,7 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa if (null !== $this->passthruLevel) { $level = $this->passthruLevel; $this->buffer = array_filter($this->buffer, function ($record) use ($level) { - return $record['level'] >= $level; + return $record->level >= $level; }); if (count($this->buffer) > 0) { $this->getHandler(end($this->buffer))->handleBatch($this->buffer); @@ -208,8 +205,6 @@ class FingersCrossedHandler extends Handler implements ProcessableHandlerInterfa * If the handler was provided as a factory callable, this will trigger the handler's instantiation. * * @return HandlerInterface - * - * @phpstan-param Record $record */ public function getHandler(LogRecord $record = null) { diff --git a/src/Monolog/Handler/FirePHPHandler.php b/src/Monolog/Handler/FirePHPHandler.php index 007c80f7..744963f1 100644 --- a/src/Monolog/Handler/FirePHPHandler.php +++ b/src/Monolog/Handler/FirePHPHandler.php @@ -19,8 +19,6 @@ use Monolog\LogRecord; * Simple FirePHP Handler (http://www.firephp.org/), which uses the Wildfire protocol. * * @author Eric Clemmons (@ericclemmons) - * - * @phpstan-import-type FormattedRecord from AbstractProcessingHandler */ class FirePHPHandler extends AbstractProcessingHandler { @@ -86,8 +84,6 @@ class FirePHPHandler extends AbstractProcessingHandler * @phpstan-return non-empty-array * * @see createHeader() - * - * @phpstan-param FormattedRecord $record */ protected function createRecordHeader(LogRecord $record): array { @@ -95,7 +91,7 @@ class FirePHPHandler extends AbstractProcessingHandler // but we're not taking advantage of that (yet), so we're using "1" for simplicity's sake. return $this->createHeader( [1, 1, 1, self::$messageIndex++], - $record['formatted'] + $record->formatted ); } diff --git a/src/Monolog/Handler/FleepHookHandler.php b/src/Monolog/Handler/FleepHookHandler.php index 5768797c..82614cb8 100644 --- a/src/Monolog/Handler/FleepHookHandler.php +++ b/src/Monolog/Handler/FleepHookHandler.php @@ -23,8 +23,6 @@ use Monolog\LogRecord; * * @see https://fleep.io/integrations/webhooks/ Fleep Webhooks Documentation * @author Ando Roots - * - * @phpstan-import-type FormattedRecord from AbstractProcessingHandler */ class FleepHookHandler extends SocketHandler { @@ -122,13 +120,11 @@ class FleepHookHandler extends SocketHandler /** * Builds the body of API call - * - * @phpstan-param FormattedRecord $record */ private function buildContent(LogRecord $record): string { $dataArray = [ - 'message' => $record['formatted'], + 'message' => $record->formatted, ]; return http_build_query($dataArray); diff --git a/src/Monolog/Handler/FlowdockHandler.php b/src/Monolog/Handler/FlowdockHandler.php index 514ebbd0..f15857ed 100644 --- a/src/Monolog/Handler/FlowdockHandler.php +++ b/src/Monolog/Handler/FlowdockHandler.php @@ -27,8 +27,6 @@ use Monolog\LogRecord; * * @author Dominik Liebler * @see https://www.flowdock.com/api/push - * - * @phpstan-import-type FormattedRecord from AbstractProcessingHandler */ class FlowdockHandler extends SocketHandler { @@ -109,12 +107,10 @@ class FlowdockHandler extends SocketHandler /** * Builds the body of API call - * - * @phpstan-param FormattedRecord $record */ private function buildContent(LogRecord $record): string { - return Utils::jsonEncode($record['formatted']); + return Utils::jsonEncode($record->formatted); } /** diff --git a/src/Monolog/Handler/GelfHandler.php b/src/Monolog/Handler/GelfHandler.php index 2198486a..b29049c4 100644 --- a/src/Monolog/Handler/GelfHandler.php +++ b/src/Monolog/Handler/GelfHandler.php @@ -45,7 +45,7 @@ class GelfHandler extends AbstractProcessingHandler */ protected function write(LogRecord $record): void { - $this->publisher->publish($record['formatted']); + $this->publisher->publish($record->formatted); } /** diff --git a/src/Monolog/Handler/GroupHandler.php b/src/Monolog/Handler/GroupHandler.php index fed86c5b..d3263275 100644 --- a/src/Monolog/Handler/GroupHandler.php +++ b/src/Monolog/Handler/GroupHandler.php @@ -19,8 +19,6 @@ use Monolog\LogRecord; * Forwards records to multiple handlers * * @author Lenar Lõhmus - * - * @phpstan-import-type Record from \Monolog\Logger */ class GroupHandler extends Handler implements ProcessableHandlerInterface, ResettableInterface { @@ -67,7 +65,6 @@ class GroupHandler extends Handler implements ProcessableHandlerInterface, Reset public function handle(LogRecord $record): bool { if ($this->processors) { - /** @var Record $record */ $record = $this->processRecord($record); } @@ -88,7 +85,6 @@ class GroupHandler extends Handler implements ProcessableHandlerInterface, Reset foreach ($records as $record) { $processed[] = $this->processRecord($record); } - /** @var Record[] $records */ $records = $processed; } diff --git a/src/Monolog/Handler/IFTTTHandler.php b/src/Monolog/Handler/IFTTTHandler.php index e5b477bc..4eaa1c95 100644 --- a/src/Monolog/Handler/IFTTTHandler.php +++ b/src/Monolog/Handler/IFTTTHandler.php @@ -55,9 +55,9 @@ class IFTTTHandler extends AbstractProcessingHandler public function write(LogRecord $record): void { $postData = [ - "value1" => $record["channel"], + "value1" => $record->channel, "value2" => $record["level_name"], - "value3" => $record["message"], + "value3" => $record->message, ]; $postString = Utils::jsonEncode($postData); diff --git a/src/Monolog/Handler/InsightOpsHandler.php b/src/Monolog/Handler/InsightOpsHandler.php index 8d796e6e..0223d5bb 100644 --- a/src/Monolog/Handler/InsightOpsHandler.php +++ b/src/Monolog/Handler/InsightOpsHandler.php @@ -72,6 +72,6 @@ class InsightOpsHandler extends SocketHandler */ protected function generateDataStream(LogRecord $record): string { - return $this->logToken . ' ' . $record['formatted']; + return $this->logToken . ' ' . $record->formatted; } } diff --git a/src/Monolog/Handler/LogEntriesHandler.php b/src/Monolog/Handler/LogEntriesHandler.php index 02d9c7d4..8fe5d869 100644 --- a/src/Monolog/Handler/LogEntriesHandler.php +++ b/src/Monolog/Handler/LogEntriesHandler.php @@ -66,6 +66,6 @@ class LogEntriesHandler extends SocketHandler */ protected function generateDataStream(LogRecord $record): string { - return $this->logToken . ' ' . $record['formatted']; + return $this->logToken . ' ' . $record->formatted; } } diff --git a/src/Monolog/Handler/LogglyHandler.php b/src/Monolog/Handler/LogglyHandler.php index a1a8e3b7..ef74ee16 100644 --- a/src/Monolog/Handler/LogglyHandler.php +++ b/src/Monolog/Handler/LogglyHandler.php @@ -34,7 +34,7 @@ class LogglyHandler extends AbstractProcessingHandler /** * Caches the curl handlers for every given endpoint. * - * @var resource[]|CurlHandle[] + * @var CurlHandle[] */ protected $curlHandlers = []; @@ -65,7 +65,7 @@ class LogglyHandler extends AbstractProcessingHandler * * @param string $endpoint * - * @return resource|CurlHandle + * @return CurlHandle */ protected function getCurlHandler(string $endpoint) { @@ -81,7 +81,7 @@ class LogglyHandler extends AbstractProcessingHandler * * @param string $endpoint * - * @return resource|CurlHandle + * @return CurlHandle */ private function loadCurlHandle(string $endpoint) { @@ -122,7 +122,7 @@ class LogglyHandler extends AbstractProcessingHandler protected function write(LogRecord $record): void { - $this->send($record["formatted"], static::ENDPOINT_SINGLE); + $this->send($record->formatted, static::ENDPOINT_SINGLE); } public function handleBatch(array $records): void @@ -130,7 +130,7 @@ class LogglyHandler extends AbstractProcessingHandler $level = $this->level; $records = array_filter($records, function ($record) use ($level) { - return ($record['level'] >= $level); + return ($record->level >= $level); }); if ($records) { diff --git a/src/Monolog/Handler/LogmaticHandler.php b/src/Monolog/Handler/LogmaticHandler.php index 29319441..b2799c2d 100644 --- a/src/Monolog/Handler/LogmaticHandler.php +++ b/src/Monolog/Handler/LogmaticHandler.php @@ -85,7 +85,7 @@ class LogmaticHandler extends SocketHandler */ protected function generateDataStream(LogRecord $record): string { - return $this->logToken . ' ' . $record['formatted']; + return $this->logToken . ' ' . $record->formatted; } /** diff --git a/src/Monolog/Handler/MailHandler.php b/src/Monolog/Handler/MailHandler.php index 6061793b..bfbe98fe 100644 --- a/src/Monolog/Handler/MailHandler.php +++ b/src/Monolog/Handler/MailHandler.php @@ -19,8 +19,6 @@ use Monolog\LogRecord; * Base class for all mail handlers * * @author Gyula Sallai - * - * @phpstan-import-type Record from \Monolog\Logger */ abstract class MailHandler extends AbstractProcessingHandler { @@ -32,10 +30,10 @@ abstract class MailHandler extends AbstractProcessingHandler $messages = []; foreach ($records as $record) { - if ($record['level'] < $this->level) { + if ($record->level < $this->level) { continue; } - /** @var Record $message */ + $message = $this->processRecord($record); $messages[] = $message; } @@ -60,7 +58,7 @@ abstract class MailHandler extends AbstractProcessingHandler */ protected function write(LogRecord $record): void { - $this->send((string) $record['formatted'], [$record]); + $this->send((string) $record->formatted, [$record]); } /** @@ -70,7 +68,7 @@ abstract class MailHandler extends AbstractProcessingHandler { $highestRecord = null; foreach ($records as $record) { - if ($highestRecord === null || $highestRecord['level'] < $record['level']) { + if ($highestRecord === null || $highestRecord['level'] < $record->level) { $highestRecord = $record; } } diff --git a/src/Monolog/Handler/MandrillHandler.php b/src/Monolog/Handler/MandrillHandler.php index 3003500e..9fe10547 100644 --- a/src/Monolog/Handler/MandrillHandler.php +++ b/src/Monolog/Handler/MandrillHandler.php @@ -28,7 +28,7 @@ class MandrillHandler extends MailHandler protected $apiKey; /** - * @psalm-param Swift_Message|callable(): Swift_Message $message + * @phpstan-param (Swift_Message|callable(): Swift_Message) $message * * @param string $apiKey A valid Mandrill API key * @param callable|Swift_Message $message An example message for real messages, only the body will be replaced diff --git a/src/Monolog/Handler/MongoDBHandler.php b/src/Monolog/Handler/MongoDBHandler.php index c5037515..50aaa1e6 100644 --- a/src/Monolog/Handler/MongoDBHandler.php +++ b/src/Monolog/Handler/MongoDBHandler.php @@ -34,12 +34,11 @@ use Monolog\LogRecord; */ class MongoDBHandler extends AbstractProcessingHandler { - /** @var \MongoDB\Collection */ - private $collection; - /** @var Client|Manager */ - private $manager; - /** @var string */ - private $namespace; + private \MongoDB\Collection $collection; + + private Client|Manager $manager; + + private string|null $namespace = null; /** * Constructor. @@ -67,12 +66,12 @@ class MongoDBHandler extends AbstractProcessingHandler protected function write(LogRecord $record): void { if (isset($this->collection)) { - $this->collection->insertOne($record['formatted']); + $this->collection->insertOne($record->formatted); } if (isset($this->manager, $this->namespace)) { $bulk = new BulkWrite; - $bulk->insert($record["formatted"]); + $bulk->insert($record->formatted); $this->manager->executeBulkWrite($this->namespace, $bulk); } } diff --git a/src/Monolog/Handler/NewRelicHandler.php b/src/Monolog/Handler/NewRelicHandler.php index 89c37e67..113aaa49 100644 --- a/src/Monolog/Handler/NewRelicHandler.php +++ b/src/Monolog/Handler/NewRelicHandler.php @@ -21,7 +21,7 @@ use Monolog\LogRecord; * Class to record a log on a NewRelic application. * Enabling New Relic High Security mode may prevent capture of useful information. * - * This handler requires a NormalizerFormatter to function and expects an array in $record['formatted'] + * This handler requires a NormalizerFormatter to function and expects an array in $record->formatted * * @see https://docs.newrelic.com/docs/agents/php-agent * @see https://docs.newrelic.com/docs/accounts-partnerships/accounts/security/high-security @@ -80,24 +80,24 @@ class NewRelicHandler extends AbstractProcessingHandler throw new MissingExtensionException('The newrelic PHP extension is required to use the NewRelicHandler'); } - if ($appName = $this->getAppName($record['context'])) { + if ($appName = $this->getAppName($record->context)) { $this->setNewRelicAppName($appName); } - if ($transactionName = $this->getTransactionName($record['context'])) { + if ($transactionName = $this->getTransactionName($record->context)) { $this->setNewRelicTransactionName($transactionName); - unset($record['formatted']['context']['transaction_name']); + unset($record->formatted['context']['transaction_name']); } - if (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Throwable) { - newrelic_notice_error($record['message'], $record['context']['exception']); - unset($record['formatted']['context']['exception']); + if (isset($record->context['exception']) && $record->context['exception'] instanceof \Throwable) { + newrelic_notice_error($record->message, $record->context['exception']); + unset($record->formatted['context']['exception']); } else { - newrelic_notice_error($record['message']); + newrelic_notice_error($record->message); } - if (isset($record['formatted']['context']) && is_array($record['formatted']['context'])) { - foreach ($record['formatted']['context'] as $key => $parameter) { + if (isset($record->formatted['context']) && is_array($record->formatted['context'])) { + foreach ($record->formatted['context'] as $key => $parameter) { if (is_array($parameter) && $this->explodeArrays) { foreach ($parameter as $paramKey => $paramValue) { $this->setNewRelicParameter('context_' . $key . '_' . $paramKey, $paramValue); @@ -108,8 +108,8 @@ class NewRelicHandler extends AbstractProcessingHandler } } - if (isset($record['formatted']['extra']) && is_array($record['formatted']['extra'])) { - foreach ($record['formatted']['extra'] as $key => $parameter) { + if (isset($record->formatted['extra']) && is_array($record->formatted['extra'])) { + foreach ($record->formatted['extra'] as $key => $parameter) { if (is_array($parameter) && $this->explodeArrays) { foreach ($parameter as $paramKey => $paramValue) { $this->setNewRelicParameter('extra_' . $key . '_' . $paramKey, $paramValue); diff --git a/src/Monolog/Handler/NullHandler.php b/src/Monolog/Handler/NullHandler.php index 54a40fee..99c1e659 100644 --- a/src/Monolog/Handler/NullHandler.php +++ b/src/Monolog/Handler/NullHandler.php @@ -48,7 +48,7 @@ class NullHandler extends Handler */ public function isHandling(LogRecord $record): bool { - return $record['level'] >= $this->level; + return $record->level >= $this->level; } /** @@ -56,6 +56,6 @@ class NullHandler extends Handler */ public function handle(LogRecord $record): bool { - return $record['level'] >= $this->level; + return $record->level >= $this->level; } } diff --git a/src/Monolog/Handler/OverflowHandler.php b/src/Monolog/Handler/OverflowHandler.php index 4673ecc7..af33424f 100644 --- a/src/Monolog/Handler/OverflowHandler.php +++ b/src/Monolog/Handler/OverflowHandler.php @@ -90,11 +90,11 @@ class OverflowHandler extends AbstractHandler implements FormattableHandlerInter */ public function handle(LogRecord $record): bool { - if ($record['level'] < $this->level) { + if ($record->level < $this->level) { return false; } - $level = $record['level']; + $level = $record->level; if (!isset($this->thresholdMap[$level])) { $this->thresholdMap[$level] = 0; diff --git a/src/Monolog/Handler/PHPConsoleHandler.php b/src/Monolog/Handler/PHPConsoleHandler.php index e06128a5..d4aeb9e9 100644 --- a/src/Monolog/Handler/PHPConsoleHandler.php +++ b/src/Monolog/Handler/PHPConsoleHandler.php @@ -38,8 +38,6 @@ use Monolog\LogRecord; * PC::debug($_SERVER); // PHP Console debugger for any type of vars * * @author Sergey Barbushin https://www.linkedin.com/in/barbushin - * - * @phpstan-import-type Record from \Monolog\Logger */ class PHPConsoleHandler extends AbstractProcessingHandler { @@ -182,46 +180,37 @@ class PHPConsoleHandler extends AbstractProcessingHandler */ protected function write(LogRecord $record): void { - if ($record['level'] < Logger::NOTICE) { + if ($record->level < Logger::NOTICE) { $this->handleDebugRecord($record); - } elseif (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Throwable) { + } elseif (isset($record->context['exception']) && $record->context['exception'] instanceof \Throwable) { $this->handleExceptionRecord($record); } else { $this->handleErrorRecord($record); } } - /** - * @phpstan-param Record $record - */ private function handleDebugRecord(LogRecord $record): void { [$tags, $filteredContext] = $this->getRecordTags($record); - $message = $record['message']; + $message = $record->message; if ($filteredContext) { $message .= ' ' . Utils::jsonEncode($this->connector->getDumper()->dump(array_filter($filteredContext)), null, true); } $this->connector->getDebugDispatcher()->dispatchDebug($message, $tags, $this->options['classesPartialsTraceIgnore']); } - /** - * @phpstan-param Record $record - */ private function handleExceptionRecord(LogRecord $record): void { - $this->connector->getErrorsDispatcher()->dispatchException($record['context']['exception']); + $this->connector->getErrorsDispatcher()->dispatchException($record->context['exception']); } - /** - * @phpstan-param Record $record - */ private function handleErrorRecord(LogRecord $record): void { $context = $record->context; $this->connector->getErrorsDispatcher()->dispatchError( $context['code'] ?? null, - $context['message'] ?? $record['message'], + $context['message'] ?? $record->message, $context['file'] ?? null, $context['line'] ?? null, $this->options['classesPartialsTraceIgnore'] diff --git a/src/Monolog/Handler/ProcessHandler.php b/src/Monolog/Handler/ProcessHandler.php index 7fcbdc78..d2c3cea9 100644 --- a/src/Monolog/Handler/ProcessHandler.php +++ b/src/Monolog/Handler/ProcessHandler.php @@ -88,7 +88,7 @@ class ProcessHandler extends AbstractProcessingHandler { $this->ensureProcessIsStarted(); - $this->writeProcessInput($record['formatted']); + $this->writeProcessInput($record->formatted); $errors = $this->readProcessErrors(); if (empty($errors) === false) { diff --git a/src/Monolog/Handler/ProcessableHandlerInterface.php b/src/Monolog/Handler/ProcessableHandlerInterface.php index 3adec7a4..9fb290fa 100644 --- a/src/Monolog/Handler/ProcessableHandlerInterface.php +++ b/src/Monolog/Handler/ProcessableHandlerInterface.php @@ -12,20 +12,19 @@ namespace Monolog\Handler; use Monolog\Processor\ProcessorInterface; +use Monolog\LogRecord; /** * Interface to describe loggers that have processors * * @author Jordi Boggiano - * - * @phpstan-import-type Record from \Monolog\Logger */ interface ProcessableHandlerInterface { /** * Adds a processor in the stack. * - * @psalm-param ProcessorInterface|callable(Record): Record $callback + * @phpstan-param ProcessorInterface|(callable(LogRecord): LogRecord) $callback * * @param ProcessorInterface|callable $callback * @return HandlerInterface self @@ -35,7 +34,7 @@ interface ProcessableHandlerInterface /** * Removes the processor on top of the stack and returns it. * - * @psalm-return ProcessorInterface|callable(Record): Record $callback + * @phpstan-return ProcessorInterface|(callable(LogRecord): LogRecord) $callback * * @throws \LogicException In case the processor stack is empty * @return callable|ProcessorInterface diff --git a/src/Monolog/Handler/ProcessableHandlerTrait.php b/src/Monolog/Handler/ProcessableHandlerTrait.php index e8e6b68c..217b2136 100644 --- a/src/Monolog/Handler/ProcessableHandlerTrait.php +++ b/src/Monolog/Handler/ProcessableHandlerTrait.php @@ -24,7 +24,7 @@ trait ProcessableHandlerTrait { /** * @var callable[] - * @phpstan-var array> + * @phpstan-var array<(callable(LogRecord): LogRecord)|ProcessorInterface> */ protected $processors = []; diff --git a/src/Monolog/Handler/PsrHandler.php b/src/Monolog/Handler/PsrHandler.php index 0fad51f2..50fee172 100644 --- a/src/Monolog/Handler/PsrHandler.php +++ b/src/Monolog/Handler/PsrHandler.php @@ -60,9 +60,9 @@ class PsrHandler extends AbstractHandler implements FormattableHandlerInterface if ($this->formatter) { $formatted = $this->formatter->format($record); - $this->logger->log(strtolower($record['level_name']), (string) $formatted, $record['context']); + $this->logger->log(strtolower($record->levelName), (string) $formatted, $record->context); } else { - $this->logger->log(strtolower($record['level_name']), $record['message'], $record['context']); + $this->logger->log(strtolower($record->levelName), $record->message, $record->context); } return false === $this->bubble; diff --git a/src/Monolog/Handler/PushoverHandler.php b/src/Monolog/Handler/PushoverHandler.php index 388e28ab..57bdff8d 100644 --- a/src/Monolog/Handler/PushoverHandler.php +++ b/src/Monolog/Handler/PushoverHandler.php @@ -22,7 +22,6 @@ use Monolog\LogRecord; * @author Sebastian Göttschkes * @see https://www.pushover.net/api * - * @phpstan-import-type FormattedRecord from AbstractProcessingHandler * @phpstan-import-type Level from \Monolog\Logger * @phpstan-import-type LevelName from \Monolog\Logger */ @@ -144,18 +143,15 @@ class PushoverHandler extends SocketHandler return $this->buildHeader($content) . $content; } - /** - * @phpstan-param FormattedRecord $record - */ private function buildContent(LogRecord $record): string { // Pushover has a limit of 512 characters on title and message combined. $maxMessageLength = 512 - strlen($this->title); - $message = ($this->useFormattedMessage) ? $record['formatted'] : $record['message']; + $message = ($this->useFormattedMessage) ? $record->formatted : $record->message; $message = Utils::substr($message, 0, $maxMessageLength); - $timestamp = $record['datetime']->getTimestamp(); + $timestamp = $record->datetime->getTimestamp(); $dataArray = [ 'token' => $this->token, @@ -165,17 +161,17 @@ class PushoverHandler extends SocketHandler 'timestamp' => $timestamp, ]; - if (isset($record['level']) && $record['level'] >= $this->emergencyLevel) { + if (isset($record->level) && $record->level >= $this->emergencyLevel) { $dataArray['priority'] = 2; $dataArray['retry'] = $this->retry; $dataArray['expire'] = $this->expire; - } elseif (isset($record['level']) && $record['level'] >= $this->highPriorityLevel) { + } elseif (isset($record->level) && $record->level >= $this->highPriorityLevel) { $dataArray['priority'] = 1; } // First determine the available parameters - $context = array_intersect_key($record['context'], $this->parameterNames); - $extra = array_intersect_key($record['extra'], $this->parameterNames); + $context = array_intersect_key($record->context, $this->parameterNames); + $extra = array_intersect_key($record->extra, $this->parameterNames); // Least important info should be merged with subsequent info $dataArray = array_merge($extra, $context, $dataArray); diff --git a/src/Monolog/Handler/RedisHandler.php b/src/Monolog/Handler/RedisHandler.php index 4c86a132..6b652ce5 100644 --- a/src/Monolog/Handler/RedisHandler.php +++ b/src/Monolog/Handler/RedisHandler.php @@ -26,12 +26,10 @@ use Monolog\LogRecord; * $log->pushHandler($redis); * * @author Thomas Tourlourat - * - * @phpstan-import-type FormattedRecord from AbstractProcessingHandler */ class RedisHandler extends AbstractProcessingHandler { - /** @var \Predis\Client|\Redis */ + /** @var \Predis\Client<\Predis\Client>|\Redis */ private $redisClient; /** @var string */ private $redisKey; @@ -39,7 +37,7 @@ class RedisHandler extends AbstractProcessingHandler protected $capSize; /** - * @param \Predis\Client|\Redis $redis The redis instance + * @param \Predis\Client<\Predis\Client>|\Redis $redis The redis instance * @param string $key The key name to push records to * @param int $capSize Number of entries to limit list size to, 0 = unlimited */ @@ -64,29 +62,27 @@ class RedisHandler extends AbstractProcessingHandler if ($this->capSize) { $this->writeCapped($record); } else { - $this->redisClient->rpush($this->redisKey, $record["formatted"]); + $this->redisClient->rpush($this->redisKey, $record->formatted); } } /** * Write and cap the collection * Writes the record to the redis list and caps its - * - * @phpstan-param FormattedRecord $record */ protected function writeCapped(LogRecord $record): void { if ($this->redisClient instanceof \Redis) { $mode = defined('\Redis::MULTI') ? \Redis::MULTI : 1; $this->redisClient->multi($mode) - ->rpush($this->redisKey, $record["formatted"]) + ->rpush($this->redisKey, $record->formatted) ->ltrim($this->redisKey, -$this->capSize, -1) ->exec(); } else { $redisKey = $this->redisKey; $capSize = $this->capSize; $this->redisClient->transaction(function ($tx) use ($record, $redisKey, $capSize) { - $tx->rpush($redisKey, $record["formatted"]); + $tx->rpush($redisKey, $record->formatted); $tx->ltrim($redisKey, -$capSize, -1); }); } diff --git a/src/Monolog/Handler/RedisPubSubHandler.php b/src/Monolog/Handler/RedisPubSubHandler.php index 4864de03..0d58ed28 100644 --- a/src/Monolog/Handler/RedisPubSubHandler.php +++ b/src/Monolog/Handler/RedisPubSubHandler.php @@ -29,13 +29,13 @@ use Monolog\LogRecord; */ class RedisPubSubHandler extends AbstractProcessingHandler { - /** @var \Predis\Client|\Redis */ + /** @var \Predis\Client<\Predis\Client>|\Redis */ private $redisClient; /** @var string */ private $channelKey; /** - * @param \Predis\Client|\Redis $redis The redis instance + * @param \Predis\Client<\Predis\Client>|\Redis $redis The redis instance * @param string $key The channel key to publish records to */ public function __construct($redis, string $key, $level = Logger::DEBUG, bool $bubble = true) @@ -55,7 +55,7 @@ class RedisPubSubHandler extends AbstractProcessingHandler */ protected function write(LogRecord $record): void { - $this->redisClient->publish($this->channelKey, $record["formatted"]); + $this->redisClient->publish($this->channelKey, $record->formatted); } /** diff --git a/src/Monolog/Handler/RollbarHandler.php b/src/Monolog/Handler/RollbarHandler.php index 05fa74e0..76b32054 100644 --- a/src/Monolog/Handler/RollbarHandler.php +++ b/src/Monolog/Handler/RollbarHandler.php @@ -82,12 +82,12 @@ class RollbarHandler extends AbstractProcessingHandler $this->initialized = true; } - $context = $record['context']; - $context = array_merge($context, $record['extra'], [ - 'level' => $this->levelMap[$record['level']], - 'monolog_level' => $record['level_name'], - 'channel' => $record['channel'], - 'datetime' => $record['datetime']->format('U'), + $context = $record->context; + $context = array_merge($context, $record->extra, [ + 'level' => $this->levelMap[$record->level], + 'monolog_level' => $record->levelName, + 'channel' => $record->channel, + 'datetime' => $record->datetime->format('U'), ]); if (isset($context['exception']) && $context['exception'] instanceof Throwable) { @@ -95,7 +95,7 @@ class RollbarHandler extends AbstractProcessingHandler unset($context['exception']); $toLog = $exception; } else { - $toLog = $record['message']; + $toLog = $record->message; } // @phpstan-ignore-next-line diff --git a/src/Monolog/Handler/RotatingFileHandler.php b/src/Monolog/Handler/RotatingFileHandler.php index dada67e1..39abfc95 100644 --- a/src/Monolog/Handler/RotatingFileHandler.php +++ b/src/Monolog/Handler/RotatingFileHandler.php @@ -118,7 +118,7 @@ class RotatingFileHandler extends StreamHandler $this->mustRotate = null === $this->url || !file_exists($this->url); } - if ($this->nextRotation <= $record['datetime']) { + if ($this->nextRotation <= $record->datetime) { $this->mustRotate = true; $this->close(); } diff --git a/src/Monolog/Handler/SamplingHandler.php b/src/Monolog/Handler/SamplingHandler.php index 1b8a2f08..39f1e0d7 100644 --- a/src/Monolog/Handler/SamplingHandler.php +++ b/src/Monolog/Handler/SamplingHandler.php @@ -27,8 +27,6 @@ use Monolog\LogRecord; * * @author Bryan Davis * @author Kunal Mehta - * - * @phpstan-import-type Record from \Monolog\Logger * @phpstan-import-type Level from \Monolog\Logger */ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInterface, FormattableHandlerInterface @@ -37,7 +35,7 @@ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInter /** * @var HandlerInterface|callable - * @phpstan-var HandlerInterface|callable(Record|array{level: Level}|null, HandlerInterface): HandlerInterface + * @phpstan-var (callable(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface */ protected $handler; @@ -47,7 +45,7 @@ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInter protected $factor; /** - * @psalm-param HandlerInterface|callable(Record|array{level: Level}|null, HandlerInterface): HandlerInterface $handler + * @phpstan-param (callable(LogRecord|null, HandlerInterface): HandlerInterface)|HandlerInterface $handler * * @param callable|HandlerInterface $handler Handler or factory callable($record|null, $samplingHandler). * @param int $factor Sample factor (e.g. 10 means every ~10th record is sampled) @@ -72,7 +70,6 @@ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInter { if ($this->isHandling($record) && mt_rand(1, $this->factor) === 1) { if ($this->processors) { - /** @var Record $record */ $record = $this->processRecord($record); } @@ -87,8 +84,6 @@ class SamplingHandler extends AbstractHandler implements ProcessableHandlerInter * * If the handler was provided as a factory callable, this will trigger the handler's instantiation. * - * @phpstan-param Record|array{level: Level}|null $record - * * @return HandlerInterface */ public function getHandler(LogRecord $record = null) diff --git a/src/Monolog/Handler/Slack/SlackRecord.php b/src/Monolog/Handler/Slack/SlackRecord.php index d20cc691..fba86225 100644 --- a/src/Monolog/Handler/Slack/SlackRecord.php +++ b/src/Monolog/Handler/Slack/SlackRecord.php @@ -24,9 +24,6 @@ use Monolog\LogRecord; * @author Haralan Dobrev * @see https://api.slack.com/incoming-webhooks * @see https://api.slack.com/docs/message-attachments - * - * @phpstan-import-type FormattedRecord from \Monolog\Handler\AbstractProcessingHandler - * @phpstan-import-type Record from \Monolog\Logger */ class SlackRecord { @@ -122,7 +119,6 @@ class SlackRecord * Returns required data in format that Slack * is expecting. * - * @phpstan-param FormattedRecord $record * @phpstan-return mixed[] */ public function getSlackData(LogRecord $record): array @@ -138,49 +134,48 @@ class SlackRecord } if ($this->formatter && !$this->useAttachment) { - /** @phpstan-ignore-next-line */ $message = $this->formatter->format($record); } else { $message = $record->message; } - $record = $this->removeExcludedFields($record); + $recordData = $this->removeExcludedFields($record); if ($this->useAttachment) { $attachment = array( - 'fallback' => $message, - 'text' => $message, - 'color' => $this->getAttachmentColor($record['level']), - 'fields' => array(), - 'mrkdwn_in' => array('fields'), - 'ts' => $record['datetime']->getTimestamp(), + 'fallback' => $message, + 'text' => $message, + 'color' => $this->getAttachmentColor($recordData['level']), + 'fields' => array(), + 'mrkdwn_in' => array('fields'), + 'ts' => $recordData['datetime']->getTimestamp(), 'footer' => $this->username, 'footer_icon' => $this->userIcon, ); if ($this->useShortAttachment) { - $attachment['title'] = $record['level_name']; + $attachment['title'] = $recordData['level_name']; } else { $attachment['title'] = 'Message'; - $attachment['fields'][] = $this->generateAttachmentField('Level', $record['level_name']); + $attachment['fields'][] = $this->generateAttachmentField('Level', $recordData['level_name']); } if ($this->includeContextAndExtra) { foreach (array('extra', 'context') as $key) { - if (empty($record[$key])) { + if (empty($recordData[$key])) { continue; } if ($this->useShortAttachment) { $attachment['fields'][] = $this->generateAttachmentField( (string) $key, - $record[$key] + $recordData[$key] ); } else { // Add all extra fields as individual fields in attachment $attachment['fields'] = array_merge( $attachment['fields'], - $this->generateAttachmentFields($record[$key]) + $this->generateAttachmentFields($recordData[$key]) ); } } @@ -360,16 +355,14 @@ class SlackRecord /** * Get a copy of record with fields excluded according to $this->excludeFields * - * @phpstan-param FormattedRecord $record - * * @return mixed[] */ private function removeExcludedFields(LogRecord $record): array { - $record = $record->toArray(); + $recordData = $record->toArray(); foreach ($this->excludeFields as $field) { $keys = explode('.', $field); - $node = &$record; + $node = &$recordData; $lastKey = end($keys); foreach ($keys as $key) { if (!isset($node[$key])) { @@ -383,6 +376,6 @@ class SlackRecord } } - return $record; + return $recordData; } } diff --git a/src/Monolog/Handler/SlackHandler.php b/src/Monolog/Handler/SlackHandler.php index 1e6e5517..4f57daee 100644 --- a/src/Monolog/Handler/SlackHandler.php +++ b/src/Monolog/Handler/SlackHandler.php @@ -22,8 +22,6 @@ use Monolog\LogRecord; * * @author Greg Kedzierski * @see https://api.slack.com/ - * - * @phpstan-import-type FormattedRecord from AbstractProcessingHandler */ class SlackHandler extends SocketHandler { @@ -117,8 +115,6 @@ class SlackHandler extends SocketHandler /** * Builds the body of API call - * - * @phpstan-param FormattedRecord $record */ private function buildContent(LogRecord $record): string { @@ -128,7 +124,6 @@ class SlackHandler extends SocketHandler } /** - * @phpstan-param FormattedRecord $record * @return string[] */ protected function prepareContentData(LogRecord $record): array diff --git a/src/Monolog/Handler/SocketHandler.php b/src/Monolog/Handler/SocketHandler.php index 44fdffa9..1d8a68f2 100644 --- a/src/Monolog/Handler/SocketHandler.php +++ b/src/Monolog/Handler/SocketHandler.php @@ -19,9 +19,6 @@ use Monolog\LogRecord; * * @author Pablo de Leon Belloc * @see http://php.net/manual/en/function.fsockopen.php - * - * @phpstan-import-type Record from \Monolog\Logger - * @phpstan-import-type FormattedRecord from AbstractProcessingHandler */ class SocketHandler extends AbstractProcessingHandler { @@ -343,12 +340,9 @@ class SocketHandler extends AbstractProcessingHandler $this->connect(); } - /** - * @phpstan-param FormattedRecord $record - */ protected function generateDataStream(LogRecord $record): string { - return (string) $record['formatted']; + return (string) $record->formatted; } /** diff --git a/src/Monolog/Handler/SqsHandler.php b/src/Monolog/Handler/SqsHandler.php index bbc2ae84..727c20a8 100644 --- a/src/Monolog/Handler/SqsHandler.php +++ b/src/Monolog/Handler/SqsHandler.php @@ -46,11 +46,11 @@ class SqsHandler extends AbstractProcessingHandler */ protected function write(LogRecord $record): void { - if (!isset($record['formatted']) || 'string' !== gettype($record['formatted'])) { + if (!isset($record->formatted) || 'string' !== gettype($record->formatted)) { throw new \InvalidArgumentException('SqsHandler accepts only formatted records as a string' . Utils::getRecordMessageForException($record)); } - $messageBody = $record['formatted']; + $messageBody = $record->formatted; if (strlen($messageBody) >= static::MAX_MESSAGE_SIZE) { $messageBody = Utils::substr($messageBody, 0, static::HEAD_MESSAGE_SIZE); } diff --git a/src/Monolog/Handler/StreamHandler.php b/src/Monolog/Handler/StreamHandler.php index b48250f0..0053db15 100644 --- a/src/Monolog/Handler/StreamHandler.php +++ b/src/Monolog/Handler/StreamHandler.php @@ -21,8 +21,6 @@ use Monolog\LogRecord; * Can be used to store into php://stderr, remote and local files, etc. * * @author Jordi Boggiano - * - * @phpstan-import-type FormattedRecord from AbstractProcessingHandler */ class StreamHandler extends AbstractProcessingHandler { @@ -170,13 +168,10 @@ class StreamHandler extends AbstractProcessingHandler /** * Write to stream * @param resource $stream - * @param array $record - * - * @phpstan-param FormattedRecord $record */ protected function streamWrite($stream, LogRecord $record): void { - fwrite($stream, (string) $record['formatted']); + fwrite($stream, (string) $record->formatted); } private function customErrorHandler(int $code, string $msg): bool diff --git a/src/Monolog/Handler/SyslogHandler.php b/src/Monolog/Handler/SyslogHandler.php index 9652e4d4..77ceaa1d 100644 --- a/src/Monolog/Handler/SyslogHandler.php +++ b/src/Monolog/Handler/SyslogHandler.php @@ -64,6 +64,6 @@ class SyslogHandler extends AbstractSyslogHandler if (!openlog($this->ident, $this->logopts, $this->facility)) { throw new \LogicException('Can\'t open syslog for ident "'.$this->ident.'" and facility "'.$this->facility.'"' . Utils::getRecordMessageForException($record)); } - syslog($this->logLevels[$record['level']], (string) $record['formatted']); + syslog($this->logLevels[$record->level], (string) $record->formatted); } } diff --git a/src/Monolog/Handler/SyslogUdpHandler.php b/src/Monolog/Handler/SyslogUdpHandler.php index c4360cbf..07feaa56 100644 --- a/src/Monolog/Handler/SyslogUdpHandler.php +++ b/src/Monolog/Handler/SyslogUdpHandler.php @@ -70,9 +70,9 @@ class SyslogUdpHandler extends AbstractSyslogHandler protected function write(LogRecord $record): void { - $lines = $this->splitMessageIntoLines($record['formatted']); + $lines = $this->splitMessageIntoLines($record->formatted); - $header = $this->makeCommonSyslogHeader($this->logLevels[$record['level']], $record['datetime']); + $header = $this->makeCommonSyslogHeader($this->logLevels[$record->level], $record->datetime); foreach ($lines as $line) { $this->socket->write($line, $header); diff --git a/src/Monolog/Handler/TelegramBotHandler.php b/src/Monolog/Handler/TelegramBotHandler.php index d44148d0..e2812c99 100644 --- a/src/Monolog/Handler/TelegramBotHandler.php +++ b/src/Monolog/Handler/TelegramBotHandler.php @@ -29,8 +29,6 @@ use Monolog\LogRecord; * @link https://core.telegram.org/bots/api * * @author Mazur Alexandr - * - * @phpstan-import-type Record from \Monolog\Logger */ class TelegramBotHandler extends AbstractProcessingHandler { @@ -186,7 +184,6 @@ class TelegramBotHandler extends AbstractProcessingHandler */ public function handleBatch(array $records): void { - /** @var Record[] $messages */ $messages = []; foreach ($records as $record) { @@ -195,7 +192,6 @@ class TelegramBotHandler extends AbstractProcessingHandler } if ($this->processors) { - /** @var Record $record */ $record = $this->processRecord($record); } @@ -212,7 +208,7 @@ class TelegramBotHandler extends AbstractProcessingHandler */ protected function write(LogRecord $record): void { - $this->send($record['formatted']); + $this->send($record->formatted); } /** diff --git a/src/Monolog/Handler/TestHandler.php b/src/Monolog/Handler/TestHandler.php index 5f5d51ea..2395889e 100644 --- a/src/Monolog/Handler/TestHandler.php +++ b/src/Monolog/Handler/TestHandler.php @@ -126,23 +126,23 @@ class TestHandler extends AbstractProcessingHandler } /** - * @param string|array $record Either a message string or an array containing message and optionally context keys that will be checked against all records + * @param string|array $recordAssertions Either a message string or an array containing message and optionally context keys that will be checked against all records * @param string|int $level Logging level value or name * - * @phpstan-param array{message: string, context?: mixed[]}|string $record + * @phpstan-param array{message: string, context?: mixed[]}|string $recordAssertions * @phpstan-param Level|LevelName|LogLevel::* $level */ - public function hasRecord(string|array $record, $level): bool + public function hasRecord(string|array $recordAssertions, $level): bool { - if (is_string($record)) { - $record = ['message' => $record]; + if (is_string($recordAssertions)) { + $recordAssertions = ['message' => $recordAssertions]; } - return $this->hasRecordThatPasses(function (LogRecord $rec) use ($record) { - if ($rec->message !== $record['message']) { + return $this->hasRecordThatPasses(function (LogRecord $rec) use ($recordAssertions) { + if ($rec->message !== $recordAssertions['message']) { return false; } - if (isset($record['context']) && $rec->context !== $record['context']) { + if (isset($recordAssertions['context']) && $rec->context !== $recordAssertions['context']) { return false; } @@ -157,9 +157,7 @@ class TestHandler extends AbstractProcessingHandler */ public function hasRecordThatContains(string $message, $level): bool { - return $this->hasRecordThatPasses(function ($rec) use ($message) { - return strpos($rec['message'], $message) !== false; - }, $level); + return $this->hasRecordThatPasses(fn (LogRecord $rec) => str_contains($rec->message, $message), $level); } /** @@ -169,16 +167,14 @@ class TestHandler extends AbstractProcessingHandler */ public function hasRecordThatMatches(string $regex, $level): bool { - return $this->hasRecordThatPasses(function (LogRecord $rec) use ($regex): bool { - return preg_match($regex, $rec->message) > 0; - }, $level); + return $this->hasRecordThatPasses(fn (LogRecord $rec) => preg_match($regex, $rec->message) > 0, $level); } /** * @param string|int $level Logging level value or name * @return bool * - * @psalm-param callable(LogRecord, int): mixed $predicate + * @phpstan-param callable(LogRecord, int): mixed $predicate * @phpstan-param Level|LevelName|LogLevel::* $level */ public function hasRecordThatPasses(callable $predicate, $level) diff --git a/src/Monolog/Handler/WhatFailureGroupHandler.php b/src/Monolog/Handler/WhatFailureGroupHandler.php index 0f83fcb8..b26f21f6 100644 --- a/src/Monolog/Handler/WhatFailureGroupHandler.php +++ b/src/Monolog/Handler/WhatFailureGroupHandler.php @@ -12,14 +12,13 @@ namespace Monolog\Handler; use Monolog\LogRecord; +use Throwable; /** * Forwards records to multiple handlers suppressing failures of each handler * and continuing through to give every handler a chance to succeed. * * @author Craig D'Amelio - * - * @phpstan-import-type Record from \Monolog\Logger */ class WhatFailureGroupHandler extends GroupHandler { @@ -29,14 +28,13 @@ class WhatFailureGroupHandler extends GroupHandler public function handle(LogRecord $record): bool { if ($this->processors) { - /** @var Record $record */ $record = $this->processRecord($record); } foreach ($this->handlers as $handler) { try { $handler->handle($record); - } catch (\Throwable $e) { + } catch (Throwable) { // What failure? } } @@ -54,14 +52,13 @@ class WhatFailureGroupHandler extends GroupHandler foreach ($records as $record) { $processed[] = $this->processRecord($record); } - /** @var Record[] $records */ $records = $processed; } foreach ($this->handlers as $handler) { try { $handler->handleBatch($records); - } catch (\Throwable $e) { + } catch (Throwable) { // What failure? } } diff --git a/src/Monolog/Handler/ZendMonitorHandler.php b/src/Monolog/Handler/ZendMonitorHandler.php index 8f974d5a..b881f492 100644 --- a/src/Monolog/Handler/ZendMonitorHandler.php +++ b/src/Monolog/Handler/ZendMonitorHandler.php @@ -21,8 +21,6 @@ use Monolog\LogRecord; * * @author Christian Bergau * @author Jason Davis - * - * @phpstan-import-type FormattedRecord from AbstractProcessingHandler */ class ZendMonitorHandler extends AbstractProcessingHandler { @@ -63,10 +61,10 @@ class ZendMonitorHandler extends AbstractProcessingHandler protected function write(LogRecord $record): void { $this->writeZendMonitorCustomEvent( - Logger::getLevelName($record['level']), - $record['message'], - $record['formatted'], - $this->levelMap[$record['level']] + Logger::getLevelName($record->level), + $record->message, + $record->formatted, + $this->levelMap[$record->level] ); } @@ -74,10 +72,8 @@ class ZendMonitorHandler extends AbstractProcessingHandler * Write to Zend Monitor Events * @param string $type Text displayed in "Class Name (custom)" field * @param string $message Text displayed in "Error String" - * @param array $formatted Displayed in Custom Variables tab + * @param array $formatted Displayed in Custom Variables tab * @param int $severity Set the event severity level (-1,0,1) - * - * @phpstan-param FormattedRecord $formatted */ protected function writeZendMonitorCustomEvent(string $type, string $message, array $formatted, int $severity): void { diff --git a/src/Monolog/Processor/GitProcessor.php b/src/Monolog/Processor/GitProcessor.php index cb80ee2f..920cbc3f 100644 --- a/src/Monolog/Processor/GitProcessor.php +++ b/src/Monolog/Processor/GitProcessor.php @@ -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; } diff --git a/src/Monolog/Processor/HostnameProcessor.php b/src/Monolog/Processor/HostnameProcessor.php index d8fa3b9f..b999b284 100644 --- a/src/Monolog/Processor/HostnameProcessor.php +++ b/src/Monolog/Processor/HostnameProcessor.php @@ -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; } diff --git a/src/Monolog/Processor/IntrospectionProcessor.php b/src/Monolog/Processor/IntrospectionProcessor.php index 6414a90c..2cbc83b4 100644 --- a/src/Monolog/Processor/IntrospectionProcessor.php +++ b/src/Monolog/Processor/IntrospectionProcessor.php @@ -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 $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); } } diff --git a/src/Monolog/Processor/MemoryPeakUsageProcessor.php b/src/Monolog/Processor/MemoryPeakUsageProcessor.php index e4b0d6d9..3e98c480 100644 --- a/src/Monolog/Processor/MemoryPeakUsageProcessor.php +++ b/src/Monolog/Processor/MemoryPeakUsageProcessor.php @@ -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; } diff --git a/src/Monolog/Processor/MemoryUsageProcessor.php b/src/Monolog/Processor/MemoryUsageProcessor.php index 281432ed..fa48d246 100644 --- a/src/Monolog/Processor/MemoryUsageProcessor.php +++ b/src/Monolog/Processor/MemoryUsageProcessor.php @@ -32,7 +32,7 @@ class MemoryUsageProcessor extends MemoryProcessor $usage = $this->formatBytes($usage); } - $record['extra']['memory_usage'] = $usage; + $record->extra['memory_usage'] = $usage; return $record; } diff --git a/src/Monolog/Processor/MercurialProcessor.php b/src/Monolog/Processor/MercurialProcessor.php index 152e1f05..7fb1340d 100644 --- a/src/Monolog/Processor/MercurialProcessor.php +++ b/src/Monolog/Processor/MercurialProcessor.php @@ -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; } diff --git a/src/Monolog/Processor/ProcessIdProcessor.php b/src/Monolog/Processor/ProcessIdProcessor.php index 074cfa4f..686c5049 100644 --- a/src/Monolog/Processor/ProcessIdProcessor.php +++ b/src/Monolog/Processor/ProcessIdProcessor.php @@ -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; } diff --git a/src/Monolog/Processor/PsrLogMessageProcessor.php b/src/Monolog/Processor/PsrLogMessageProcessor.php index 339aec51..5f6aede1 100644 --- a/src/Monolog/Processor/PsrLogMessageProcessor.php +++ b/src/Monolog/Processor/PsrLogMessageProcessor.php @@ -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); } } diff --git a/src/Monolog/Processor/UidProcessor.php b/src/Monolog/Processor/UidProcessor.php index 58133b42..85d56c3a 100644 --- a/src/Monolog/Processor/UidProcessor.php +++ b/src/Monolog/Processor/UidProcessor.php @@ -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; } diff --git a/src/Monolog/Processor/WebProcessor.php b/src/Monolog/Processor/WebProcessor.php index a1d3dc86..27496ebb 100644 --- a/src/Monolog/Processor/WebProcessor.php +++ b/src/Monolog/Processor/WebProcessor.php @@ -86,7 +86,7 @@ class WebProcessor implements ProcessorInterface return $record; } - $record['extra'] = $this->appendExtraFields($record['extra']); + $record->extra = $this->appendExtraFields($record->extra); return $record; } diff --git a/src/Monolog/Test/TestCase.php b/src/Monolog/Test/TestCase.php index 42e1c870..83981636 100644 --- a/src/Monolog/Test/TestCase.php +++ b/src/Monolog/Test/TestCase.php @@ -26,7 +26,8 @@ use Monolog\Formatter\FormatterInterface; class TestCase extends \PHPUnit\Framework\TestCase { /** - * @param mixed[] $context + * @param array $context + * @param array $extra * * @phpstan-param Level $level */ diff --git a/tests/Monolog/Formatter/JsonFormatterTest.php b/tests/Monolog/Formatter/JsonFormatterTest.php index ea22ec08..38fd66c8 100644 --- a/tests/Monolog/Formatter/JsonFormatterTest.php +++ b/tests/Monolog/Formatter/JsonFormatterTest.php @@ -43,7 +43,7 @@ class JsonFormatterTest extends TestCase $formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_JSON, false); $record = $this->getRecord(); - $this->assertEquals('{"message":"test","context":{},"level":300,"level_name":"WARNING","channel":"test","datetime":"'.$record['datetime']->format('Y-m-d\TH:i:s.uP').'","extra":{}}', $formatter->format($record)); + $this->assertEquals('{"message":"test","context":{},"level":300,"level_name":"WARNING","channel":"test","datetime":"'.$record->datetime->format('Y-m-d\TH:i:s.uP').'","extra":{}}', $formatter->format($record)); } /** @@ -66,7 +66,7 @@ class JsonFormatterTest extends TestCase "level": 300, "level_name": "WARNING", "channel": "test", - "datetime": "'.$record['datetime']->format('Y-m-d\TH:i:s.uP').'", + "datetime": "'.$record->datetime->format('Y-m-d\TH:i:s.uP').'", "extra": {} }', $formatter->format($record) @@ -74,7 +74,7 @@ class JsonFormatterTest extends TestCase $formatter->setJsonPrettyPrint(false); $record = $this->getRecord(); - $this->assertEquals('{"message":"test","context":{},"level":300,"level_name":"WARNING","channel":"test","datetime":"'.$record['datetime']->format('Y-m-d\TH:i:s.uP').'","extra":{}}', $formatter->format($record)); + $this->assertEquals('{"message":"test","context":{},"level":300,"level_name":"WARNING","channel":"test","datetime":"'.$record->datetime->format('Y-m-d\TH:i:s.uP').'","extra":{}}', $formatter->format($record)); } /** @@ -187,7 +187,7 @@ class JsonFormatterTest extends TestCase $record = $this->getRecord( context: ['field_resource' => opendir(__DIR__)], ); - $this->assertEquals('{"message":"test","context":{"field_resource":"[resource(stream)]"},"level":300,"level_name":"WARNING","channel":"test","datetime":"'.$record['datetime']->format('Y-m-d\TH:i:s.uP').'","extra":{}}', $formatter->format($record)); + $this->assertEquals('{"message":"test","context":{"field_resource":"[resource(stream)]"},"level":300,"level_name":"WARNING","channel":"test","datetime":"'.$record->datetime->format('Y-m-d\TH:i:s.uP').'","extra":{}}', $formatter->format($record)); } /** diff --git a/tests/Monolog/Formatter/LogglyFormatterTest.php b/tests/Monolog/Formatter/LogglyFormatterTest.php index 2eff4ac5..de0aeb85 100644 --- a/tests/Monolog/Formatter/LogglyFormatterTest.php +++ b/tests/Monolog/Formatter/LogglyFormatterTest.php @@ -36,6 +36,6 @@ class LogglyFormatterTest extends TestCase $formatted_decoded = json_decode($formatter->format($record), true); $this->assertArrayNotHasKey("datetime", $formatted_decoded); $this->assertArrayHasKey("timestamp", $formatted_decoded); - $this->assertEquals($record["datetime"]->format('Y-m-d\TH:i:s.uO'), $formatted_decoded["timestamp"]); + $this->assertEquals($record->datetime->format('Y-m-d\TH:i:s.uO'), $formatted_decoded["timestamp"]); } } diff --git a/tests/Monolog/Handler/BufferHandlerTest.php b/tests/Monolog/Handler/BufferHandlerTest.php index 4867d182..15c77b38 100644 --- a/tests/Monolog/Handler/BufferHandlerTest.php +++ b/tests/Monolog/Handler/BufferHandlerTest.php @@ -145,7 +145,7 @@ class BufferHandlerTest extends TestCase $test = new TestHandler(); $handler = new BufferHandler($test); $handler->pushProcessor(function ($record) { - $record['extra']['foo'] = true; + $record->extra['foo'] = true; return $record; }); diff --git a/tests/Monolog/Handler/DeduplicationHandlerTest.php b/tests/Monolog/Handler/DeduplicationHandlerTest.php index b5c760c7..86c7c8a5 100644 --- a/tests/Monolog/Handler/DeduplicationHandlerTest.php +++ b/tests/Monolog/Handler/DeduplicationHandlerTest.php @@ -122,7 +122,7 @@ class DeduplicationHandlerTest extends TestCase // log is written as none of them are duplicate $handler->flush(); $this->assertSame( - $record['datetime']->getTimestamp() . ":ERROR:test\n" . + $record->datetime->getTimestamp() . ":ERROR:test\n" . $record2['datetime']->getTimestamp() . ":CRITICAL:test\n" . $record3['datetime']->getTimestamp() . ":CRITICAL:test\n", file_get_contents(sys_get_temp_dir() . '/monolog_dedup.log') @@ -144,7 +144,7 @@ class DeduplicationHandlerTest extends TestCase // log should now contain the new errors and the previous one that was recent enough $this->assertSame( $record3['datetime']->getTimestamp() . ":CRITICAL:test\n" . - $record['datetime']->getTimestamp() . ":ERROR:test\n" . + $record->datetime->getTimestamp() . ":ERROR:test\n" . $record2['datetime']->getTimestamp() . ":CRITICAL:test\n", file_get_contents(sys_get_temp_dir() . '/monolog_dedup.log') ); diff --git a/tests/Monolog/Handler/DoctrineCouchDBHandlerTest.php b/tests/Monolog/Handler/DoctrineCouchDBHandlerTest.php index 1d5aa14b..35330681 100644 --- a/tests/Monolog/Handler/DoctrineCouchDBHandlerTest.php +++ b/tests/Monolog/Handler/DoctrineCouchDBHandlerTest.php @@ -38,7 +38,7 @@ class DoctrineCouchDBHandlerTest extends TestCase 'level' => Logger::WARNING, 'level_name' => 'WARNING', 'channel' => 'test', - 'datetime' => (string) $record['datetime'], + 'datetime' => (string) $record->datetime, 'extra' => [], ]; diff --git a/tests/Monolog/Handler/FallbackGroupHandlerTest.php b/tests/Monolog/Handler/FallbackGroupHandlerTest.php index f92a5afe..0cb149bc 100644 --- a/tests/Monolog/Handler/FallbackGroupHandlerTest.php +++ b/tests/Monolog/Handler/FallbackGroupHandlerTest.php @@ -98,7 +98,7 @@ class FallbackGroupHandlerTest extends TestCase $test = new TestHandler(); $handler = new FallbackGroupHandler([$test]); $handler->pushProcessor(function ($record) { - $record['extra']['foo'] = true; + $record->extra['foo'] = true; return $record; }); @@ -118,12 +118,12 @@ class FallbackGroupHandlerTest extends TestCase $testHandlers = [$testHandlerOne, $testHandlerTwo]; $handler = new FallbackGroupHandler($testHandlers); $handler->pushProcessor(function ($record) { - $record['extra']['foo'] = true; + $record->extra['foo'] = true; return $record; }); $handler->pushProcessor(function ($record) { - $record['extra']['foo2'] = true; + $record->extra['foo2'] = true; return $record; }); diff --git a/tests/Monolog/Handler/FilterHandlerTest.php b/tests/Monolog/Handler/FilterHandlerTest.php index 6058fade..49ecb12b 100644 --- a/tests/Monolog/Handler/FilterHandlerTest.php +++ b/tests/Monolog/Handler/FilterHandlerTest.php @@ -110,7 +110,7 @@ class FilterHandlerTest extends TestCase $handler = new FilterHandler($test, Logger::DEBUG, Logger::EMERGENCY); $handler->pushProcessor( function ($record) { - $record['extra']['foo'] = true; + $record->extra['foo'] = true; return $record; } diff --git a/tests/Monolog/Handler/GelfHandlerTest.php b/tests/Monolog/Handler/GelfHandlerTest.php index eecc2e4c..93117140 100644 --- a/tests/Monolog/Handler/GelfHandlerTest.php +++ b/tests/Monolog/Handler/GelfHandlerTest.php @@ -56,8 +56,8 @@ class GelfHandlerTest extends TestCase $expectedMessage ->setLevel(7) ->setFacility("test") - ->setShortMessage($record['message']) - ->setTimestamp($record['datetime']) + ->setShortMessage($record->message) + ->setTimestamp($record->datetime) ; $messagePublisher = $this->getMessagePublisher(); @@ -77,8 +77,8 @@ class GelfHandlerTest extends TestCase $expectedMessage ->setLevel(4) ->setFacility("test") - ->setShortMessage($record['message']) - ->setTimestamp($record['datetime']) + ->setShortMessage($record->message) + ->setTimestamp($record->datetime) ; $messagePublisher = $this->getMessagePublisher(); @@ -105,8 +105,8 @@ class GelfHandlerTest extends TestCase ->setLevel(4) ->setFacility("test") ->setHost("mysystem") - ->setShortMessage($record['message']) - ->setTimestamp($record['datetime']) + ->setShortMessage($record->message) + ->setTimestamp($record->datetime) ->setAdditional("EXTblarg", 'yep') ->setAdditional("CTXfrom", 'logger') ; diff --git a/tests/Monolog/Handler/GroupHandlerTest.php b/tests/Monolog/Handler/GroupHandlerTest.php index e2a2a147..97680db3 100644 --- a/tests/Monolog/Handler/GroupHandlerTest.php +++ b/tests/Monolog/Handler/GroupHandlerTest.php @@ -78,7 +78,7 @@ class GroupHandlerTest extends TestCase $test = new TestHandler(); $handler = new GroupHandler([$test]); $handler->pushProcessor(function ($record) { - $record['extra']['foo'] = true; + $record->extra['foo'] = true; return $record; }); @@ -96,12 +96,12 @@ class GroupHandlerTest extends TestCase $testHandlers = [new TestHandler(), new TestHandler()]; $handler = new GroupHandler($testHandlers); $handler->pushProcessor(function ($record) { - $record['extra']['foo'] = true; + $record->extra['foo'] = true; return $record; }); $handler->pushProcessor(function ($record) { - $record['extra']['foo2'] = true; + $record->extra['foo2'] = true; return $record; }); diff --git a/tests/Monolog/Handler/MailHandlerTest.php b/tests/Monolog/Handler/MailHandlerTest.php index 5a52819c..d85a7077 100644 --- a/tests/Monolog/Handler/MailHandlerTest.php +++ b/tests/Monolog/Handler/MailHandlerTest.php @@ -65,7 +65,7 @@ class MailHandlerTest extends TestCase $record = $this->getRecord(); $records = [$record]; - $records[0]['formatted'] = '['.$record['datetime'].'] test.WARNING: test [] []'."\n"; + $records[0]['formatted'] = '['.$record->datetime.'] test.WARNING: test [] []'."\n"; $handler->expects($this->once()) ->method('send') diff --git a/tests/Monolog/Handler/MongoDBHandlerTest.php b/tests/Monolog/Handler/MongoDBHandlerTest.php index 6cc976a7..6fbdc5f3 100644 --- a/tests/Monolog/Handler/MongoDBHandlerTest.php +++ b/tests/Monolog/Handler/MongoDBHandlerTest.php @@ -44,7 +44,7 @@ class MongoDBHandlerTest extends TestCase $record = $this->getRecord(); $expected = $record->toArray(); - $expected['datetime'] = new \MongoDB\BSON\UTCDateTime((int) floor(((float) $record['datetime']->format('U.u')) * 1000)); + $expected['datetime'] = new \MongoDB\BSON\UTCDateTime((int) floor(((float) $record->datetime->format('U.u')) * 1000)); $collection->expects($this->once()) ->method('insertOne') diff --git a/tests/Monolog/Handler/NewRelicHandlerTest.php b/tests/Monolog/Handler/NewRelicHandlerTest.php index a02a6efe..b60f0b78 100644 --- a/tests/Monolog/Handler/NewRelicHandlerTest.php +++ b/tests/Monolog/Handler/NewRelicHandlerTest.php @@ -67,7 +67,7 @@ class NewRelicHandlerTest extends TestCase public function testThehandlerCanAddExtraParamsToTheNewRelicTrace() { $record = $this->getRecord(Logger::ERROR, 'log message'); - $record['extra'] = ['c' => 'd']; + $record->extra = ['c' => 'd']; $handler = new StubNewRelicHandler(); $handler->handle($record); @@ -78,7 +78,7 @@ class NewRelicHandlerTest extends TestCase public function testThehandlerCanAddExplodedExtraParamsToTheNewRelicTrace() { $record = $this->getRecord(Logger::ERROR, 'log message'); - $record['extra'] = ['c' => ['key1' => 'value1', 'key2' => 'value2']]; + $record->extra = ['c' => ['key1' => 'value1', 'key2' => 'value2']]; $handler = new StubNewRelicHandler(Logger::ERROR, true, self::$appname, true); $handler->handle($record); @@ -92,7 +92,7 @@ class NewRelicHandlerTest extends TestCase public function testThehandlerCanAddExtraContextAndParamsToTheNewRelicTrace() { $record = $this->getRecord(Logger::ERROR, 'log message', ['a' => 'b']); - $record['extra'] = ['c' => 'd']; + $record->extra = ['c' => 'd']; $handler = new StubNewRelicHandler(); $handler->handle($record); diff --git a/tests/Monolog/Handler/Slack/SlackRecordTest.php b/tests/Monolog/Handler/Slack/SlackRecordTest.php index 10738955..563bec72 100644 --- a/tests/Monolog/Handler/Slack/SlackRecordTest.php +++ b/tests/Monolog/Handler/Slack/SlackRecordTest.php @@ -168,7 +168,7 @@ class SlackRecordTest extends TestCase ->expects($this->any()) ->method('format') ->will($this->returnCallback(function ($record) { - return $record['message'] . 'test'; + return $record->message . 'test'; })); $formatter2 = $this->createMock('Monolog\\Formatter\\FormatterInterface'); @@ -176,7 +176,7 @@ class SlackRecordTest extends TestCase ->expects($this->any()) ->method('format') ->will($this->returnCallback(function ($record) { - return $record['message'] . 'test1'; + return $record->message . 'test1'; })); $message = 'Test message'; @@ -345,7 +345,7 @@ class SlackRecordTest extends TestCase $attachment = $data['attachments'][0]; $this->assertArrayHasKey('ts', $attachment); - $this->assertSame($record['datetime']->getTimestamp(), $attachment['ts']); + $this->assertSame($record->datetime->getTimestamp(), $attachment['ts']); } public function testContextHasException() @@ -361,9 +361,9 @@ class SlackRecordTest extends TestCase $record = $this->getRecord( Logger::WARNING, 'test', - array('info' => array('library' => 'monolog', 'author' => 'Jordi')) + context: array('info' => array('library' => 'monolog', 'author' => 'Jordi')), + extra: array('tags' => array('web', 'cli')), ); - $record['extra'] = array('tags' => array('web', 'cli')); $slackRecord = new SlackRecord(null, null, true, null, false, true, array('context.info.library', 'extra.tags.1')); $data = $slackRecord->getSlackData($record); diff --git a/tests/Monolog/Handler/SlackWebhookHandlerTest.php b/tests/Monolog/Handler/SlackWebhookHandlerTest.php index 36990ebf..5ff26225 100644 --- a/tests/Monolog/Handler/SlackWebhookHandlerTest.php +++ b/tests/Monolog/Handler/SlackWebhookHandlerTest.php @@ -50,7 +50,7 @@ class SlackWebhookHandlerTest extends TestCase ), 'title' => 'Message', 'mrkdwn_in' => array('fields'), - 'ts' => $record['datetime']->getTimestamp(), + 'ts' => $record->datetime->getTimestamp(), 'footer' => null, 'footer_icon' => null, ), diff --git a/tests/Monolog/Handler/WhatFailureGroupHandlerTest.php b/tests/Monolog/Handler/WhatFailureGroupHandlerTest.php index 6b8d0d8e..3d0d3b12 100644 --- a/tests/Monolog/Handler/WhatFailureGroupHandlerTest.php +++ b/tests/Monolog/Handler/WhatFailureGroupHandlerTest.php @@ -78,7 +78,7 @@ class WhatFailureGroupHandlerTest extends TestCase $test = new TestHandler(); $handler = new WhatFailureGroupHandler([$test]); $handler->pushProcessor(function ($record) { - $record['extra']['foo'] = true; + $record->extra['foo'] = true; return $record; }); @@ -96,12 +96,12 @@ class WhatFailureGroupHandlerTest extends TestCase $testHandlers = array(new TestHandler(), new TestHandler()); $handler = new WhatFailureGroupHandler($testHandlers); $handler->pushProcessor(function ($record) { - $record['extra']['foo'] = true; + $record->extra['foo'] = true; return $record; }); $handler->pushProcessor(function ($record) { - $record['extra']['foo2'] = true; + $record->extra['foo2'] = true; return $record; }); @@ -127,7 +127,7 @@ class WhatFailureGroupHandlerTest extends TestCase $exception = new ExceptionTestHandler(); $handler = new WhatFailureGroupHandler([$exception, $test, $exception]); $handler->pushProcessor(function ($record) { - $record['extra']['foo'] = true; + $record->extra['foo'] = true; return $record; }); diff --git a/tests/Monolog/Handler/ZendMonitorHandlerTest.php b/tests/Monolog/Handler/ZendMonitorHandlerTest.php index e8fe55c5..42622ffb 100644 --- a/tests/Monolog/Handler/ZendMonitorHandlerTest.php +++ b/tests/Monolog/Handler/ZendMonitorHandlerTest.php @@ -32,7 +32,7 @@ class ZendMonitorHandlerTest extends TestCase { $record = $this->getRecord(); $formatterResult = [ - 'message' => $record['message'], + 'message' => $record->message, ]; $zendMonitor = $this->getMockBuilder('Monolog\Handler\ZendMonitorHandler') @@ -56,10 +56,10 @@ class ZendMonitorHandlerTest extends TestCase $zendMonitor->expects($this->once()) ->method('writeZendMonitorCustomEvent') ->with( - Logger::getLevelName($record['level']), - $record['message'], + Logger::getLevelName($record->level), + $record->message, $formatterResult, - $levelMap[$record['level']] + $levelMap[$record->level] ); $zendMonitor->handle($record); diff --git a/tests/Monolog/LoggerTest.php b/tests/Monolog/LoggerTest.php index f49a6f45..9ba62f74 100644 --- a/tests/Monolog/LoggerTest.php +++ b/tests/Monolog/LoggerTest.php @@ -82,7 +82,7 @@ class LoggerTest extends TestCase $logger->pushHandler($handler); $logger->warning('test'); list($record) = $handler->getRecords(); - $this->assertEquals('foo', $record['channel']); + $this->assertEquals('foo', $record->channel); } /** @@ -229,13 +229,13 @@ class LoggerTest extends TestCase $handler = new TestHandler; $logger->pushHandler($handler); $logger->pushProcessor(function ($record) { - $record['extra']['win'] = true; + $record->extra['win'] = true; return $record; }); $logger->error('test'); list($record) = $handler->getRecords(); - $this->assertTrue($record['extra']['win']); + $this->assertTrue($record->extra['win']); } /** @@ -478,7 +478,7 @@ class LoggerTest extends TestCase $logger->pushHandler($handler); $logger->{$method}('test'); list($record) = $handler->getRecords(); - $this->assertEquals($expectedLevel, $record['level']); + $this->assertEquals($expectedLevel, $record->level); } public function logMethodProvider() @@ -508,7 +508,7 @@ class LoggerTest extends TestCase $logger->pushHandler($handler); $logger->info('test'); list($record) = $handler->getRecords(); - $this->assertEquals($tz, $record['datetime']->getTimezone()); + $this->assertEquals($tz, $record->datetime->getTimezone()); } public function setTimezoneProvider() @@ -538,8 +538,8 @@ class LoggerTest extends TestCase $logger->info('test'); list($record) = $handler->getRecords(); - $this->assertEquals($tz, $record['datetime']->getTimezone()); - $this->assertEquals($dt->format('Y/m/d H:i'), $record['datetime']->format('Y/m/d H:i'), 'Time should match timezone with microseconds set to: '.var_export($microseconds, true)); + $this->assertEquals($tz, $record->datetime->getTimezone()); + $this->assertEquals($dt->format('Y/m/d H:i'), $record->datetime->format('Y/m/d H:i'), 'Time should match timezone with microseconds set to: '.var_export($microseconds, true)); } } @@ -561,8 +561,8 @@ class LoggerTest extends TestCase $logger->info('test'); list($record) = $handler->getRecords(); - $this->assertEquals($tz, $record['datetime']->getTimezone()); - $this->assertEquals($dt->format('Y/m/d H:i'), $record['datetime']->format('Y/m/d H:i'), 'Time should match timezone with microseconds set to: '.var_export($microseconds, true)); + $this->assertEquals($tz, $record->datetime->getTimezone()); + $this->assertEquals($dt->format('Y/m/d H:i'), $record->datetime->format('Y/m/d H:i'), 'Time should match timezone with microseconds set to: '.var_export($microseconds, true)); } } @@ -588,8 +588,8 @@ class LoggerTest extends TestCase $logger->pushHandler($handler); $logger->info('test'); list($record) = $handler->getRecords(); - $this->{$assert}('000000', $record['datetime']->format('u')); - $this->assertSame($record['datetime']->format($assertFormat), (string) $record['datetime']); + $this->{$assert}('000000', $record->datetime->format('u')); + $this->assertSame($record->datetime->format($assertFormat), (string) $record->datetime); } public function useMicrosecondTimestampsProvider() @@ -648,7 +648,7 @@ class LoggerTest extends TestCase $logger->setExceptionHandler(function ($e, $record) use ($that) { $that->assertEquals($e->getMessage(), 'Some handler exception'); $that->assertInstanceOf(LogRecord::class, $record); - $that->assertEquals($record['message'], 'test'); + $that->assertEquals($record->message, 'test'); }); $handler = $this->getMockBuilder('Monolog\Handler\HandlerInterface')->getMock(); $handler->expects($this->any()) diff --git a/tests/Monolog/Processor/GitProcessorTest.php b/tests/Monolog/Processor/GitProcessorTest.php index 0059e6d3..4b0e1b0c 100644 --- a/tests/Monolog/Processor/GitProcessorTest.php +++ b/tests/Monolog/Processor/GitProcessorTest.php @@ -23,7 +23,7 @@ class GitProcessorTest extends TestCase $processor = new GitProcessor(); $record = $processor($this->getRecord()); - $this->assertArrayHasKey('git', $record['extra']); - $this->assertTrue(!is_array($record['extra']['git']['branch'])); + $this->assertArrayHasKey('git', $record->extra); + $this->assertTrue(!is_array($record->extra['git']['branch'])); } } diff --git a/tests/Monolog/Processor/HostnameProcessorTest.php b/tests/Monolog/Processor/HostnameProcessorTest.php index c5745751..2329ea85 100644 --- a/tests/Monolog/Processor/HostnameProcessorTest.php +++ b/tests/Monolog/Processor/HostnameProcessorTest.php @@ -22,9 +22,9 @@ class HostnameProcessorTest extends TestCase { $processor = new HostnameProcessor(); $record = $processor($this->getRecord()); - $this->assertArrayHasKey('hostname', $record['extra']); - $this->assertIsString($record['extra']['hostname']); - $this->assertNotEmpty($record['extra']['hostname']); - $this->assertEquals(gethostname(), $record['extra']['hostname']); + $this->assertArrayHasKey('hostname', $record->extra); + $this->assertIsString($record->extra['hostname']); + $this->assertNotEmpty($record->extra['hostname']); + $this->assertEquals(gethostname(), $record->extra['hostname']); } } diff --git a/tests/Monolog/Processor/IntrospectionProcessorTest.php b/tests/Monolog/Processor/IntrospectionProcessorTest.php index cb1d8b91..ac5b523d 100644 --- a/tests/Monolog/Processor/IntrospectionProcessorTest.php +++ b/tests/Monolog/Processor/IntrospectionProcessorTest.php @@ -47,10 +47,10 @@ class IntrospectionProcessorTest extends TestCase $tester = new \Acme\Tester; $tester->test($handler, $this->getRecord()); list($record) = $handler->getRecords(); - $this->assertEquals(__FILE__, $record['extra']['file']); - $this->assertEquals(18, $record['extra']['line']); - $this->assertEquals('Acme\Tester', $record['extra']['class']); - $this->assertEquals('test', $record['extra']['function']); + $this->assertEquals(__FILE__, $record->extra['file']); + $this->assertEquals(18, $record->extra['line']); + $this->assertEquals('Acme\Tester', $record->extra['class']); + $this->assertEquals('test', $record->extra['function']); } public function testProcessorFromFunc() @@ -58,10 +58,10 @@ class IntrospectionProcessorTest extends TestCase $handler = $this->getHandler(); \Acme\tester($handler, $this->getRecord()); list($record) = $handler->getRecords(); - $this->assertEquals(__FILE__, $record['extra']['file']); - $this->assertEquals(24, $record['extra']['line']); - $this->assertEquals(null, $record['extra']['class']); - $this->assertEquals('Acme\tester', $record['extra']['function']); + $this->assertEquals(__FILE__, $record->extra['file']); + $this->assertEquals(24, $record->extra['line']); + $this->assertEquals(null, $record->extra['class']); + $this->assertEquals('Acme\tester', $record->extra['function']); } public function testLevelTooLow() diff --git a/tests/Monolog/Processor/MemoryPeakUsageProcessorTest.php b/tests/Monolog/Processor/MemoryPeakUsageProcessorTest.php index 964fbbe2..0ff304ae 100644 --- a/tests/Monolog/Processor/MemoryPeakUsageProcessorTest.php +++ b/tests/Monolog/Processor/MemoryPeakUsageProcessorTest.php @@ -23,8 +23,8 @@ class MemoryPeakUsageProcessorTest extends TestCase { $processor = new MemoryPeakUsageProcessor(); $record = $processor($this->getRecord()); - $this->assertArrayHasKey('memory_peak_usage', $record['extra']); - $this->assertMatchesRegularExpression('#[0-9.]+ (M|K)?B$#', $record['extra']['memory_peak_usage']); + $this->assertArrayHasKey('memory_peak_usage', $record->extra); + $this->assertMatchesRegularExpression('#[0-9.]+ (M|K)?B$#', $record->extra['memory_peak_usage']); } /** @@ -35,8 +35,8 @@ class MemoryPeakUsageProcessorTest extends TestCase { $processor = new MemoryPeakUsageProcessor(true, false); $record = $processor($this->getRecord()); - $this->assertArrayHasKey('memory_peak_usage', $record['extra']); - $this->assertIsInt($record['extra']['memory_peak_usage']); - $this->assertGreaterThan(0, $record['extra']['memory_peak_usage']); + $this->assertArrayHasKey('memory_peak_usage', $record->extra); + $this->assertIsInt($record->extra['memory_peak_usage']); + $this->assertGreaterThan(0, $record->extra['memory_peak_usage']); } } diff --git a/tests/Monolog/Processor/MemoryUsageProcessorTest.php b/tests/Monolog/Processor/MemoryUsageProcessorTest.php index 22c047c2..a68c71ea 100644 --- a/tests/Monolog/Processor/MemoryUsageProcessorTest.php +++ b/tests/Monolog/Processor/MemoryUsageProcessorTest.php @@ -23,8 +23,8 @@ class MemoryUsageProcessorTest extends TestCase { $processor = new MemoryUsageProcessor(); $record = $processor($this->getRecord()); - $this->assertArrayHasKey('memory_usage', $record['extra']); - $this->assertMatchesRegularExpression('#[0-9.]+ (M|K)?B$#', $record['extra']['memory_usage']); + $this->assertArrayHasKey('memory_usage', $record->extra); + $this->assertMatchesRegularExpression('#[0-9.]+ (M|K)?B$#', $record->extra['memory_usage']); } /** @@ -35,8 +35,8 @@ class MemoryUsageProcessorTest extends TestCase { $processor = new MemoryUsageProcessor(true, false); $record = $processor($this->getRecord()); - $this->assertArrayHasKey('memory_usage', $record['extra']); - $this->assertIsInt($record['extra']['memory_usage']); - $this->assertGreaterThan(0, $record['extra']['memory_usage']); + $this->assertArrayHasKey('memory_usage', $record->extra); + $this->assertIsInt($record->extra['memory_usage']); + $this->assertGreaterThan(0, $record->extra['memory_usage']); } } diff --git a/tests/Monolog/Processor/MercurialProcessorTest.php b/tests/Monolog/Processor/MercurialProcessorTest.php index 9028e41e..2e20bae1 100644 --- a/tests/Monolog/Processor/MercurialProcessorTest.php +++ b/tests/Monolog/Processor/MercurialProcessorTest.php @@ -35,8 +35,8 @@ class MercurialProcessorTest extends TestCase $processor = new MercurialProcessor(); $record = $processor($this->getRecord()); - $this->assertArrayHasKey('hg', $record['extra']); - $this->assertTrue(!is_array($record['extra']['hg']['branch'])); - $this->assertTrue(!is_array($record['extra']['hg']['revision'])); + $this->assertArrayHasKey('hg', $record->extra); + $this->assertTrue(!is_array($record->extra['hg']['branch'])); + $this->assertTrue(!is_array($record->extra['hg']['revision'])); } } diff --git a/tests/Monolog/Processor/ProcessIdProcessorTest.php b/tests/Monolog/Processor/ProcessIdProcessorTest.php index 0b3446fa..57de7220 100644 --- a/tests/Monolog/Processor/ProcessIdProcessorTest.php +++ b/tests/Monolog/Processor/ProcessIdProcessorTest.php @@ -22,9 +22,9 @@ class ProcessIdProcessorTest extends TestCase { $processor = new ProcessIdProcessor(); $record = $processor($this->getRecord()); - $this->assertArrayHasKey('process_id', $record['extra']); - $this->assertIsInt($record['extra']['process_id']); - $this->assertGreaterThan(0, $record['extra']['process_id']); - $this->assertEquals(getmypid(), $record['extra']['process_id']); + $this->assertArrayHasKey('process_id', $record->extra); + $this->assertIsInt($record->extra['process_id']); + $this->assertGreaterThan(0, $record->extra['process_id']); + $this->assertEquals(getmypid(), $record->extra['process_id']); } } diff --git a/tests/Monolog/Processor/TagProcessorTest.php b/tests/Monolog/Processor/TagProcessorTest.php index da84378b..db729e54 100644 --- a/tests/Monolog/Processor/TagProcessorTest.php +++ b/tests/Monolog/Processor/TagProcessorTest.php @@ -24,7 +24,7 @@ class TagProcessorTest extends TestCase $processor = new TagProcessor($tags); $record = $processor($this->getRecord()); - $this->assertEquals($tags, $record['extra']['tags']); + $this->assertEquals($tags, $record->extra['tags']); } /** @@ -36,14 +36,14 @@ class TagProcessorTest extends TestCase $processor = new TagProcessor($tags); $record = $processor($this->getRecord()); - $this->assertEquals($tags, $record['extra']['tags']); + $this->assertEquals($tags, $record->extra['tags']); $processor->setTags(['a', 'b']); $record = $processor($this->getRecord()); - $this->assertEquals(['a', 'b'], $record['extra']['tags']); + $this->assertEquals(['a', 'b'], $record->extra['tags']); $processor->addTags(['a', 'c', 'foo' => 'bar']); $record = $processor($this->getRecord()); - $this->assertEquals(['a', 'b', 'a', 'c', 'foo' => 'bar'], $record['extra']['tags']); + $this->assertEquals(['a', 'b', 'a', 'c', 'foo' => 'bar'], $record->extra['tags']); } } diff --git a/tests/Monolog/Processor/UidProcessorTest.php b/tests/Monolog/Processor/UidProcessorTest.php index 927d5648..d9288acd 100644 --- a/tests/Monolog/Processor/UidProcessorTest.php +++ b/tests/Monolog/Processor/UidProcessorTest.php @@ -22,7 +22,7 @@ class UidProcessorTest extends TestCase { $processor = new UidProcessor(); $record = $processor($this->getRecord()); - $this->assertArrayHasKey('uid', $record['extra']); + $this->assertArrayHasKey('uid', $record->extra); } public function testGetUid() diff --git a/tests/Monolog/Processor/WebProcessorTest.php b/tests/Monolog/Processor/WebProcessorTest.php index 3f994893..5a7ac299 100644 --- a/tests/Monolog/Processor/WebProcessorTest.php +++ b/tests/Monolog/Processor/WebProcessorTest.php @@ -28,12 +28,12 @@ class WebProcessorTest extends TestCase $processor = new WebProcessor($server); $record = $processor($this->getRecord()); - $this->assertEquals($server['REQUEST_URI'], $record['extra']['url']); - $this->assertEquals($server['REMOTE_ADDR'], $record['extra']['ip']); - $this->assertEquals($server['REQUEST_METHOD'], $record['extra']['http_method']); - $this->assertEquals($server['HTTP_REFERER'], $record['extra']['referrer']); - $this->assertEquals($server['SERVER_NAME'], $record['extra']['server']); - $this->assertEquals($server['UNIQUE_ID'], $record['extra']['unique_id']); + $this->assertEquals($server['REQUEST_URI'], $record->extra['url']); + $this->assertEquals($server['REMOTE_ADDR'], $record->extra['ip']); + $this->assertEquals($server['REQUEST_METHOD'], $record->extra['http_method']); + $this->assertEquals($server['HTTP_REFERER'], $record->extra['referrer']); + $this->assertEquals($server['SERVER_NAME'], $record->extra['server']); + $this->assertEquals($server['UNIQUE_ID'], $record->extra['unique_id']); } public function testProcessorDoNothingIfNoRequestUri() @@ -44,7 +44,7 @@ class WebProcessorTest extends TestCase ]; $processor = new WebProcessor($server); $record = $processor($this->getRecord()); - $this->assertEmpty($record['extra']); + $this->assertEmpty($record->extra); } public function testProcessorReturnNullIfNoHttpReferer() @@ -57,7 +57,7 @@ class WebProcessorTest extends TestCase ]; $processor = new WebProcessor($server); $record = $processor($this->getRecord()); - $this->assertNull($record['extra']['referrer']); + $this->assertNull($record->extra['referrer']); } public function testProcessorDoesNotAddUniqueIdIfNotPresent() @@ -70,7 +70,7 @@ class WebProcessorTest extends TestCase ]; $processor = new WebProcessor($server); $record = $processor($this->getRecord()); - $this->assertFalse(isset($record['extra']['unique_id'])); + $this->assertFalse(isset($record->extra['unique_id'])); } public function testProcessorAddsOnlyRequestedExtraFields() @@ -85,7 +85,7 @@ class WebProcessorTest extends TestCase $processor = new WebProcessor($server, ['url', 'http_method']); $record = $processor($this->getRecord()); - $this->assertSame(['url' => 'A', 'http_method' => 'C'], $record['extra']); + $this->assertSame(['url' => 'A', 'http_method' => 'C'], $record->extra); } public function testProcessorAddsOnlyRequestedExtraFieldsIncludingOptionalFields() @@ -98,7 +98,7 @@ class WebProcessorTest extends TestCase $processor = new WebProcessor($server, array('url')); $record = $processor($this->getRecord()); - $this->assertSame(array('url' => 'A'), $record['extra']); + $this->assertSame(array('url' => 'A'), $record->extra); } public function testProcessorConfiguringOfExtraFields() @@ -113,7 +113,7 @@ class WebProcessorTest extends TestCase $processor = new WebProcessor($server, ['url' => 'REMOTE_ADDR']); $record = $processor($this->getRecord()); - $this->assertSame(['url' => 'B'], $record['extra']); + $this->assertSame(['url' => 'B'], $record->extra); } public function testInvalidData() diff --git a/tests/Monolog/PsrLogCompatTest.php b/tests/Monolog/PsrLogCompatTest.php index eaeb3552..529b7d29 100644 --- a/tests/Monolog/PsrLogCompatTest.php +++ b/tests/Monolog/PsrLogCompatTest.php @@ -44,7 +44,7 @@ class PsrLogCompatTest extends TestCase return strtolower($match[0]); }; - return preg_replace_callback('{^[A-Z]+}', $lower, $record['formatted']); + return preg_replace_callback('{^[A-Z]+}', $lower, $record->formatted); }; return array_map($convert, $this->handler->getRecords());