Example use case:

 use MD\Foundation\LogLevels;
 use Psr\Log\LogLevel;
 use Psr\Log\LoggerInterface;

 class SMSLogger implements LoggerInterface
 {
     public function log($level, $message, array $context) {
         if (LogLevels::isHigherLevel($level, LogLevel::ALERT, true)) {
             $this->sendSms($message, $context);
         }
     }
 }

It is useful when you want to filter out some log messages based on their importance, as PSR-3 doesn't really define the hierarchy here.

Constants This class defines the following constants:

LogLevels::EMERGENCY

600

LogLevels::ALERT

550

LogLevels::CRITICAL

500

LogLevels::ERROR

400

LogLevels::WARNING

300

LogLevels::NOTICE

250

LogLevels::INFO

200

LogLevels::DEBUG

100

Methods This class defines the following methods:

static evaluateLevel (string $level) -> int

Evaluates the given PSR log level as an integer.

Example:

 echo \MD\Foundation\LogLevels::evaluateLevel(\Psr\Log\LogLevel::CRITICAL);
 // -> 500
Arguments:
string $level

One of \Psr\Log\LogLevel constants.

Returns:
int
Throws:
MD\Foundation\Exceptions\InvalidArgumentException

When unrecognized log level.

static isHigherLevel (string $level, string $against, boolean $inclusive = false) -> boolean

Checks if the given level is higher than the other one.

Example:

 echo \MD\Foundation\LogLevels::isHigherLevel(\Psr\Log\LogLevel::CRITICAL, \PSR\Log\LogLevel::WARNING);
 // -> true
Arguments:
string $level

Level to be compared. One of \Psr\Log\LogLevel constants.

string $against

Level to be compared against. One of \Psr\Log\LogLevel constants.

boolean $inclusive

[optional] Should the comparison be inclusive, ie. higher than or equal. Default: false.

Returns:
boolean

static isLowerLevel (string $level, string $against, boolean $inclusive = false) -> boolean

Checks if the given level is lower than the other one.

Example:

 echo \MD\Foundation\LogLevels::isLowerLevel(\Psr\Log\LogLevel::CRITICAL, \PSR\Log\LogLevel::WARNING);
 // -> false
Arguments:
string $level

Level to be compared. One of \Psr\Log\LogLevel constants.

string $against

Level to be compared against. One of \Psr\Log\LogLevel constants.

boolean $inclusive

[optional] Should the comparison be inclusive, ie. lower than or equal. Default: false.

Returns:
boolean