Skip to content

Commit

Permalink
feat: upgrade monolog and adjust some deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
alperbuulut committed Mar 12, 2024
1 parent db77d35 commit dfa161e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"php": ">=8.1 < 8.3",
"psr/log": "^2.0||^3.0",
"wecodemore/wordpress-early-hook": "^1.1.0",
"monolog/monolog": "^2.3.5"
"monolog/monolog": "^3.0"
},
"require-dev": {
"brain/monkey": "^2.6.1",
Expand Down
28 changes: 17 additions & 11 deletions src/LogLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@

namespace Inpsyde\Wonolog;

use Monolog\Logger;
use Monolog\Level;

/**
* Utility object used to build default min logging level based WordPress and environment settings.
* It also has a method to check the validity of a value as level identifier.
*/
abstract class LogLevel
{
public const DEBUG = Logger::DEBUG;
public const INFO = Logger::INFO;
public const NOTICE = Logger::NOTICE;
public const WARNING = Logger::WARNING;
public const ERROR = Logger::ERROR;
public const CRITICAL = Logger::CRITICAL;
public const ALERT = Logger::ALERT;
public const EMERGENCY = Logger::EMERGENCY;
public const DEBUG = Level::Debug;
public const INFO = Level::Info;
public const NOTICE = Level::Notice;
public const WARNING = Level::Warning;
public const ERROR = Level::Error;
public const CRITICAL = Level::Critical;
public const ALERT = Level::Alert;
public const EMERGENCY = Level::Emergency;

/**
* @var int|null
Expand All @@ -45,7 +45,13 @@ abstract class LogLevel
*/
final public static function allLevels(): array
{
return Logger::getLevels();
$levels = [];
foreach ( Level::VALUES as $value ) {
$level = Level::fromValue($value);
$levels[$value] = $level->name;
}

return array_flip($levels);
}

/**
Expand All @@ -69,7 +75,7 @@ final public static function defaultMinLevel(): int
// If no valid level is defined via env var, then let's resort to WP constants.
if (!$minLevel) {
$const = defined('WP_DEBUG_LOG') ? 'WP_DEBUG_LOG' : 'WP_DEBUG';
$minLevel = (defined($const) && constant($const)) ? Logger::DEBUG : Logger::WARNING;
$minLevel = (defined($const) && constant($const)) ? Level::Debug : Level::Warning;
}

self::$minLevel = $minLevel;
Expand Down

0 comments on commit dfa161e

Please sign in to comment.