Skip to content

Commit

Permalink
Add LogRecord class, drop PHP <8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Mar 21, 2022
1 parent f2f66cd commit 22c8b19
Show file tree
Hide file tree
Showing 111 changed files with 501 additions and 361 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,10 @@ jobs:
strategy:
matrix:
php-version:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
# disabled for now as phpspec/prophecy does not allow 8.1
# - "8.1"
- "8.1"
dependencies: [highest]
include:
- php-version: "7.2"
dependencies: lowest
- php-version: "8.0"
- php-version: "8.1"
dependencies: lowest

steps:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.2"
- "8.0"
- "8.1"

steps:
- name: "Checkout"
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -44,8 +44,7 @@ jobs:
run: 'composer require ${{ env.COMPOSER_FLAGS }} mongodb/mongodb --dev --no-update'

- name: "Install latest dependencies"
# --ignore-platform-req=php here needed as long as elasticsearch/elasticsearch does not support php 8
run: "composer update ${{ env.COMPOSER_FLAGS }} --ignore-platform-req=php"
run: "composer update ${{ env.COMPOSER_FLAGS }}"

- name: Run PHPStan
run: composer phpstan
15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
}
],
"require": {
"php": ">=7.2",
"psr/log": "^1.0.1 || ^2.0 || ^3.0"
"php": ">=8.1",
"psr/log": "^2.0 || ^3.0"
},
"require-dev": {
"aws/aws-sdk-php": "^2.4.9 || ^3.0",
Expand All @@ -25,12 +25,11 @@
"php-amqplib/php-amqplib": "~2.4 || ^3",
"php-console/php-console": "^3.1.3",
"phpspec/prophecy": "^1.6.1",
"phpunit/phpunit": "^8.5",
"phpunit/phpunit": "^9",
"predis/predis": "^1.1",
"rollbar/rollbar": "^1.3 || ^2 || ^3",
"rollbar/rollbar": "^3",
"ruflin/elastica": ">=0.90@dev",
"swiftmailer/swiftmailer": "^5.3|^6.0",
"phpstan/phpstan": "^0.12.91"
"phpstan/phpstan": "^1.4"
},
"suggest": {
"graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server",
Expand All @@ -56,11 +55,11 @@
"psr-4": {"Monolog\\": "tests/Monolog"}
},
"provide": {
"psr/log-implementation": "1.0.0 || 2.0.0 || 3.0.0"
"psr/log-implementation": "3.0.0"
},
"extra": {
"branch-alias": {
"dev-main": "2.x-dev"
"dev-main": "3.x-dev"
}
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion doc/04-extending.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PDOHandler extends AbstractProcessingHandler
parent::__construct($level, $bubble);
}

protected function write(array $record): void
protected function write(LogRecord $record): void
{
if (!$this->initialized) {
$this->initialize();
Expand Down
3 changes: 2 additions & 1 deletion src/Monolog/Formatter/ChromePHPFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Monolog\Formatter;

use Monolog\Logger;
use Monolog\LogRecord;

/**
* Formats a log message according to the ChromePHP array format
Expand Down Expand Up @@ -39,7 +40,7 @@ class ChromePHPFormatter implements FormatterInterface
/**
* {@inheritDoc}
*/
public function format(array $record)
public function format(LogRecord $record)
{
// Retrieve the line and file if set and remove them from the formatted extra
$backtrace = 'unknown';
Expand Down
7 changes: 2 additions & 5 deletions src/Monolog/Formatter/ElasticaFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
namespace Monolog\Formatter;

use Elastica\Document;
use Monolog\LogRecord;

/**
* Format a log message into an Elastica Document
*
* @author Jelle Vink <jelle.vink@gmail.com>
*
* @phpstan-import-type Record from \Monolog\Logger
*/
class ElasticaFormatter extends NormalizerFormatter
{
Expand Down Expand Up @@ -48,7 +47,7 @@ public function __construct(string $index, ?string $type)
/**
* {@inheritDoc}
*/
public function format(array $record)
public function format(LogRecord $record)
{
$record = parent::format($record);

Expand All @@ -71,8 +70,6 @@ public function getType(): string

/**
* Convert a log message into an Elastica Document
*
* @phpstan-param Record $record
*/
protected function getDocument(array $record): Document
{
Expand Down
5 changes: 3 additions & 2 deletions src/Monolog/Formatter/ElasticsearchFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Monolog\Formatter;

use DateTimeInterface;
use Monolog\LogRecord;

/**
* Format a log message into an Elasticsearch record
Expand Down Expand Up @@ -46,7 +47,7 @@ public function __construct(string $index, string $type)
/**
* {@inheritDoc}
*/
public function format(array $record)
public function format(LogRecord $record)
{
$record = parent::format($record);

Expand Down Expand Up @@ -79,7 +80,7 @@ public function getType(): string
* @param mixed[] $record Log message
* @return mixed[]
*/
protected function getDocument(array $record): array
protected function getDocument(LogRecord $record): array
{
$record['_index'] = $this->index;
$record['_type'] = $this->type;
Expand Down
4 changes: 3 additions & 1 deletion src/Monolog/Formatter/FlowdockFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Monolog\Formatter;

use Monolog\LogRecord;

/**
* formats the record to be used in the FlowdockHandler
*
Expand Down Expand Up @@ -39,7 +41,7 @@ public function __construct(string $source, string $sourceEmail)
*
* @return mixed[]
*/
public function format(array $record): array
public function format(LogRecord $record): array
{
$tags = [
'#logs',
Expand Down
3 changes: 2 additions & 1 deletion src/Monolog/Formatter/FluentdFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Monolog\Formatter;

use Monolog\Utils;
use Monolog\LogRecord;

/**
* Class FluentdFormatter
Expand Down Expand Up @@ -55,7 +56,7 @@ public function isUsingLevelsInTag(): bool
return $this->levelTag;
}

public function format(array $record): string
public function format(LogRecord $record): string
{
$tag = $record['channel'];
if ($this->levelTag) {
Expand Down
14 changes: 5 additions & 9 deletions src/Monolog/Formatter/FormatterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,28 @@

namespace Monolog\Formatter;

use Monolog\LogRecord;

/**
* Interface for formatters
*
* @author Jordi Boggiano <j.boggiano@seld.be>
*
* @phpstan-import-type Record from \Monolog\Logger
*/
interface FormatterInterface
{
/**
* Formats a log record.
*
* @param array $record A record to format
* @param LogRecord $record A record to format
* @return mixed The formatted record
*
* @phpstan-param Record $record
*/
public function format(array $record);
public function format(LogRecord $record);

/**
* Formats a set of log records.
*
* @param array $records A set of records to format
* @param array<LogRecord> $records A set of records to format
* @return mixed The formatted set of records
*
* @phpstan-param Record[] $records
*/
public function formatBatch(array $records);
}
3 changes: 2 additions & 1 deletion src/Monolog/Formatter/GelfMessageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Monolog\Logger;
use Gelf\Message;
use Monolog\Utils;
use Monolog\LogRecord;

/**
* Serializes a log message to GELF
Expand Down Expand Up @@ -83,7 +84,7 @@ public function __construct(?string $systemName = null, ?string $extraPrefix = n
/**
* {@inheritDoc}
*/
public function format(array $record): Message
public function format(LogRecord $record): Message
{
$context = $extra = [];
if (isset($record['context'])) {
Expand Down
3 changes: 2 additions & 1 deletion src/Monolog/Formatter/HtmlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Monolog\Logger;
use Monolog\Utils;
use Monolog\LogRecord;

/**
* Formats incoming records into an HTML table
Expand Down Expand Up @@ -83,7 +84,7 @@ protected function addTitle(string $title, int $level): string
*
* @return string The formatted record
*/
public function format(array $record): string
public function format(LogRecord $record): string
{
$output = $this->addTitle($record['level_name'], $record['level']);
$output .= '<table cellspacing="1" width="100%" class="monolog-output">';
Expand Down
3 changes: 2 additions & 1 deletion src/Monolog/Formatter/JsonFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Monolog\Formatter;

use Throwable;
use Monolog\LogRecord;

/**
* Encodes whatever record data is passed to it as json
Expand Down Expand Up @@ -72,7 +73,7 @@ public function isAppendingNewlines(): bool
/**
* {@inheritDoc}
*/
public function format(array $record): string
public function format(LogRecord $record): string
{
$normalized = $this->normalize($record);

Expand Down
3 changes: 2 additions & 1 deletion src/Monolog/Formatter/LineFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Monolog\Formatter;

use Monolog\Utils;
use Monolog\LogRecord;

/**
* Formats incoming records into a one-line string
Expand Down Expand Up @@ -76,7 +77,7 @@ public function ignoreEmptyContextAndExtra(bool $ignore = true): self
/**
* {@inheritDoc}
*/
public function format(array $record): string
public function format(LogRecord $record): string
{
$vars = parent::format($record);

Expand Down
4 changes: 3 additions & 1 deletion src/Monolog/Formatter/LogglyFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Monolog\Formatter;

use Monolog\LogRecord;

/**
* Encodes message information into JSON in a format compatible with Loggly.
*
Expand All @@ -33,7 +35,7 @@ public function __construct(int $batchMode = self::BATCH_MODE_NEWLINES, bool $ap
* @see https://www.loggly.com/docs/automated-parsing/#json
* @see \Monolog\Formatter\JsonFormatter::format()
*/
public function format(array $record): string
public function format(LogRecord $record): string
{
if (isset($record["datetime"]) && ($record["datetime"] instanceof \DateTimeInterface)) {
$record["timestamp"] = $record["datetime"]->format("Y-m-d\TH:i:s.uO");
Expand Down
4 changes: 3 additions & 1 deletion src/Monolog/Formatter/LogmaticFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Monolog\Formatter;

use Monolog\LogRecord;

/**
* Encodes message information into JSON in a format compatible with Logmatic.
*
Expand Down Expand Up @@ -50,7 +52,7 @@ public function setAppname(string $appname): self
* @see http://doc.logmatic.io/docs/basics-to-send-data
* @see \Monolog\Formatter\JsonFormatter::format()
*/
public function format(array $record): string
public function format(LogRecord $record): string
{
if (!empty($this->hostname)) {
$record["hostname"] = $this->hostname;
Expand Down
4 changes: 3 additions & 1 deletion src/Monolog/Formatter/LogstashFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Monolog\Formatter;

use Monolog\LogRecord;

/**
* Serializes a log message to Logstash Event Format
*
Expand Down Expand Up @@ -61,7 +63,7 @@ public function __construct(string $applicationName, ?string $systemName = null,
/**
* {@inheritDoc}
*/
public function format(array $record): string
public function format(LogRecord $record): string
{
$record = parent::format($record);

Expand Down
3 changes: 2 additions & 1 deletion src/Monolog/Formatter/MongoDBFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use MongoDB\BSON\Type;
use MongoDB\BSON\UTCDateTime;
use Monolog\Utils;
use Monolog\LogRecord;

/**
* Formats a record for use with the MongoDBHandler.
Expand Down Expand Up @@ -46,7 +47,7 @@ public function __construct(int $maxNestingLevel = 3, bool $exceptionTraceAsStri
*
* @return mixed[]
*/
public function format(array $record): array
public function format(LogRecord $record): array
{
/** @var mixed[] $res */
$res = $this->formatArray($record);
Expand Down

0 comments on commit 22c8b19

Please sign in to comment.