. */ namespace App\Entity\LogSystem; use \Psr\Log\LogLevel as PSRLogLevel; enum LogLevel: int { case EMERGENCY = 0; case ALERT = 1; case CRITICAL = 2; case ERROR = 3; case WARNING = 4; case NOTICE = 5; case INFO = 6; case DEBUG = 7; /** * Converts the current log level to a PSR-3 log level string. * @return string */ public function toPSR3LevelString(): string { return match ($this) { self::EMERGENCY => PSRLogLevel::EMERGENCY, self::ALERT => PSRLogLevel::ALERT, self::CRITICAL => PSRLogLevel::CRITICAL, self::ERROR => PSRLogLevel::ERROR, self::WARNING => PSRLogLevel::WARNING, self::NOTICE => PSRLogLevel::NOTICE, self::INFO => PSRLogLevel::INFO, self::DEBUG => PSRLogLevel::DEBUG, }; } /** * Creates a log level (enum) from a PSR-3 log level string. * @param string $level * @return self */ public static function fromPSR3LevelString(string $level): self { return match ($level) { PSRLogLevel::EMERGENCY => self::EMERGENCY, PSRLogLevel::ALERT => self::ALERT, PSRLogLevel::CRITICAL => self::CRITICAL, PSRLogLevel::ERROR => self::ERROR, PSRLogLevel::WARNING => self::WARNING, PSRLogLevel::NOTICE => self::NOTICE, PSRLogLevel::INFO => self::INFO, PSRLogLevel::DEBUG => self::DEBUG, default => throw new \InvalidArgumentException("Invalid log level: $level"), }; } /** * Checks if the current log level is more important than the given one. * @param LogLevel $other * @return bool */ public function moreImportThan(self $other): bool { //Smaller values are more important return $this->value < $other->value; } /** * Checks if the current log level is more important or equal than the given one. * @param LogLevel $other * @return bool */ public function moreImportOrEqualThan(self $other): bool { //Smaller values are more important return $this->value <= $other->value; } /** * Checks if the current log level is less important than the given one. * @param LogLevel $other * @return bool */ public function lessImportThan(self $other): bool { //Bigger values are less important return $this->value > $other->value; } /** * Checks if the current log level is less important or equal than the given one. * @param LogLevel $other * @return bool */ public function lessImportOrEqualThan(self $other): bool { //Bigger values are less important return $this->value >= $other->value; } }