Bugfixing legacy loglevel

pull/6482/head
Philipp Holzer 2019-01-07 21:54:40 +01:00 zatwierdzone przez Hypolite Petovan
rodzic c38782731f
commit 9e0be97703
2 zmienionych plików z 16 dodań i 12 usunięć

Wyświetl plik

@ -83,9 +83,7 @@ class Logger extends BaseObject
return; return;
} }
if (is_int($loglevel)) { $loglevel = self::mapLegacyConfigDebugLevel((string)$loglevel);
$loglevel = self::mapLegacyConfigDebugLevel($loglevel);
}
LoggerFactory::addStreamHandler($logger, $logfile, $loglevel); LoggerFactory::addStreamHandler($logger, $logfile, $loglevel);
@ -107,7 +105,7 @@ class Logger extends BaseObject
* Mapping a legacy level to the PSR-3 compliant levels * Mapping a legacy level to the PSR-3 compliant levels
* @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel * @see https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#5-psrlogloglevel
* *
* @param int $level the level to be mapped * @param mixed $level the level to be mapped
* *
* @return string the PSR-3 compliant level * @return string the PSR-3 compliant level
*/ */
@ -115,26 +113,26 @@ class Logger extends BaseObject
{ {
switch ($level) { switch ($level) {
// legacy WARNING // legacy WARNING
case 0: case "0":
return LogLevel::ERROR; return LogLevel::ERROR;
// legacy INFO // legacy INFO
case 1: case "1":
return LogLevel::WARNING; return LogLevel::WARNING;
// legacy TRACE // legacy TRACE
case 2: case "2":
return LogLevel::NOTICE; return LogLevel::NOTICE;
// legacy DEBUG // legacy DEBUG
case 3: case "3":
return LogLevel::INFO; return LogLevel::INFO;
// legacy DATA // legacy DATA
case 4: case "4":
return LogLevel::DEBUG; return LogLevel::DEBUG;
// legacy ALL // legacy ALL
case 5: case "5":
return LogLevel::DEBUG; return LogLevel::DEBUG;
// default if nothing set // default if nothing set
default: default:
return LogLevel::NOTICE; return $level;
} }
} }

Wyświetl plik

@ -75,7 +75,13 @@ class LoggerFactory
public static function addStreamHandler($logger, $stream, $level = LogLevel::NOTICE) public static function addStreamHandler($logger, $stream, $level = LogLevel::NOTICE)
{ {
if ($logger instanceof Monolog\Logger) { if ($logger instanceof Monolog\Logger) {
$fileHandler = new Monolog\Handler\StreamHandler($stream, Monolog\Logger::toMonologLevel($level)); $loglevel = Monolog\Logger::toMonologLevel($level);
// fallback to notice if an invalid loglevel is set
if (!is_int($loglevel)) {
$loglevel = LogLevel::NOTICE;
}
$fileHandler = new Monolog\Handler\StreamHandler($stream, $loglevel);
$formatter = new Monolog\Formatter\LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n"); $formatter = new Monolog\Formatter\LineFormatter("%datetime% %channel% [%level_name%]: %message% %context% %extra%\n");
$fileHandler->setFormatter($formatter); $fileHandler->setFormatter($formatter);