Browse Source

Bugfixing legacy loglevel

pull/6482/head
Philipp Holzer 2 years ago
committed by Hypolite Petovan
parent
commit
9e0be97703
2 changed files with 16 additions and 12 deletions
  1. +9
    -11
      src/Core/Logger.php
  2. +7
    -1
      src/Util/LoggerFactory.php

+ 9
- 11
src/Core/Logger.php View File

@ -83,9 +83,7 @@ class Logger extends BaseObject
return;
}
if (is_int($loglevel)) {
$loglevel = self::mapLegacyConfigDebugLevel($loglevel);
}
$loglevel = self::mapLegacyConfigDebugLevel((string)$loglevel);
LoggerFactory::addStreamHandler($logger, $logfile, $loglevel);
@ -107,7 +105,7 @@ class Logger extends BaseObject
* 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
*
* @param int $level the level to be mapped
* @param mixed $level the level to be mapped
*
* @return string the PSR-3 compliant level
*/
@ -115,26 +113,26 @@ class Logger extends BaseObject
{
switch ($level) {
// legacy WARNING
case 0:
case "0":
return LogLevel::ERROR;
// legacy INFO
case 1:
case "1":
return LogLevel::WARNING;
// legacy TRACE
case 2:
case "2":
return LogLevel::NOTICE;
// legacy DEBUG
case 3:
case "3":
return LogLevel::INFO;
// legacy DATA
case 4:
case "4":
return LogLevel::DEBUG;
// legacy ALL
case 5:
case "5":
return LogLevel::DEBUG;
// default if nothing set
default:
return LogLevel::NOTICE;
return $level;
}
}


+ 7
- 1
src/Util/LoggerFactory.php View File

@ -75,7 +75,13 @@ class LoggerFactory
public static function addStreamHandler($logger, $stream, $level = LogLevel::NOTICE)
{
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");
$fileHandler->setFormatter($formatter);


Loading…
Cancel
Save