-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert level/levelName to enums (#1656)
- Loading branch information
Showing
138 changed files
with
1,295 additions
and
1,214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,6 @@ composer.phar | |
phpunit.xml | ||
composer.lock | ||
.DS_Store | ||
.php_cs.cache | ||
.php-cs-fixer.cache | ||
.hg | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
namespace Monolog\Formatter; | ||
|
||
use Monolog\Level; | ||
use Monolog\Logger; | ||
use Gelf\Message; | ||
use Monolog\Utils; | ||
|
@@ -21,8 +22,6 @@ | |
* @see http://docs.graylog.org/en/latest/pages/gelf.html | ||
* | ||
* @author Matt Lehner <[email protected]> | ||
* | ||
* @phpstan-import-type Level from \Monolog\Logger | ||
*/ | ||
class GelfMessageFormatter extends NormalizerFormatter | ||
{ | ||
|
@@ -50,21 +49,20 @@ class GelfMessageFormatter extends NormalizerFormatter | |
|
||
/** | ||
* Translates Monolog log levels to Graylog2 log priorities. | ||
* | ||
* @var array<int, int> | ||
* | ||
* @phpstan-var array<Level, int> | ||
*/ | ||
private $logLevels = [ | ||
Logger::DEBUG => 7, | ||
Logger::INFO => 6, | ||
Logger::NOTICE => 5, | ||
Logger::WARNING => 4, | ||
Logger::ERROR => 3, | ||
Logger::CRITICAL => 2, | ||
Logger::ALERT => 1, | ||
Logger::EMERGENCY => 0, | ||
]; | ||
private function getGraylog2Priority(Level $level): int | ||
{ | ||
return match ($level) { | ||
Level::Debug => 7, | ||
Level::Info => 6, | ||
Level::Notice => 5, | ||
Level::Warning => 4, | ||
Level::Error => 3, | ||
Level::Critical => 2, | ||
Level::Alert => 1, | ||
Level::Emergency => 0, | ||
}; | ||
} | ||
|
||
public function __construct(?string $systemName = null, ?string $extraPrefix = null, string $contextPrefix = 'ctxt_', ?int $maxLength = null) | ||
{ | ||
|
@@ -101,7 +99,7 @@ public function format(LogRecord $record): Message | |
->setTimestamp($record->datetime) | ||
->setShortMessage((string) $record->message) | ||
->setHost($this->systemName) | ||
->setLevel($this->logLevels[$record->level]); | ||
->setLevel($this->getGraylog2Priority($record->level)); | ||
|
||
// message length + system name length + 200 for padding / metadata | ||
$len = 200 + strlen((string) $record->message) + strlen($this->systemName); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.