Static (and simple) way to enable Debug mode with a level

@param int $level
963347
static function enable(Int $level = 0)
    {
        if (!self::$instance)
            self::$instance  = new self($level);

        if (!self::$locked)
            self::$instance->level = $level;
    }
802011
protected function handleHeader($level)
    {
        if ($this->parser->isStartTag) {
            $this->out(str_repeat('#', $level) . ' ', true);
        } else {
            $this->setLineBreaks(2);
        }
    }
393016
protected function log(/*# string */ $level, /*# string */ $message)
    {
        if ($this->debug_mode) {
            $this->debugger->log(
                $level,
                $message,
                [ 'className' => get_class($this) ]
            );
        }
        return $this;
    }
747530
public function debug($str) {
        if ($this->_level >= self::DEBUG) {
            $this->put("$str ".$this->caller(), self::DEBUG);
        }
    }
619840
protected function phpErrorLevel($level) {
        switch ($level) {
            case E_NOTICE:
            case E_USER_NOTICE:
            case E_STRICT:
            case E_DEPRECATED:
            case E_USER_DEPRECATED:
                return LogLevel::NOTICE;

            case E_WARNING:
            case E_USER_WARNING:
            case E_COMPILE_WARNING:
            case E_CORE_WARNING:
                return LogLevel::WARNING;

            case E_ERROR:
            case E_USER_ERROR:
            case E_PARSE:
            case E_COMPILE_ERROR:
            case E_CORE_ERROR:
            case E_RECOVERABLE_ERROR:
                return LogLevel::ERROR;
        }

        return LogLevel::ERROR;
    }
48620
private static function log(string $level, string $message, array $context = [])
    {
        if (static::$logger !== null) {
            static::$logger->$level($message, $context);
        }
    }
1061437
private function validateLogLevel($level)
    {
        $map = Logger::getLogLevelMap();
        $level = (string) $level;

        if (isset($map[$level]) || isset(array_flip($map)[strtoupper($level)])) {
            return true;
        }

        throw new InvalidArgumentException("Severity level '$level' is not defined.");
    }
561501
public static function clearLog($level = null)
    {
        foreach (self::$files as $fileName => $fileLevel) {
            if ($level === null || $level === $fileLevel) {
                $fileName = self::$path . $fileName;

                if (file_exists($fileName)) {
                    @unlink($fileName);
                }
                continue;
            }
        }

        // Restart current logger instance.
        self::$instance = null;
        self::start();
    }
359656
public function setDebug($debug)
    {
        $this->debug = strtolower((string) $debug);

        $message = sprintf("Set debug flag to [%s].", $this->debug);
        $this->log($message, Project::MSG_DEBUG);
    }
127091
public function debug($flag)
    {
        $this->debug = (in_array($flag, [true, false])) ? $flag : false;

        return $this;
    }
418471
public function setNextQueryIsolationLevel(string $level) : void
    {
        if (!\in_array($level, static::ISOLATION_LEVELS, true)) {
            throw new InvalidIsolationLevelException();
        }

        $this->nextQueryIsolationLevel = $level;
    }
838963
public static function setReportLevel(string $level): Matcha {
            if( ReportLevel::has($level) === false ) {
                throw new InvalidArgumentException(sprintf('The report level should be one of the following: %s, %s given', 
                    implode(', ', ReportLevel::availables()),
                    $level
                )); 
            }

            static::$reportLevel = $level;
            
            return new static;
        }
1150651
private static function levelToPriority($level)
    {
        switch ($level) {
            case LogLevel::EMERGENCY:
                return LOG_EMERG;
            case LogLevel::ALERT:
                return LOG_ALERT;
            case LogLevel::CRITICAL:
                return LOG_CRIT;
            case LogLevel::ERROR:
                return LOG_ERR;
            case LogLevel::WARNING:
                return LOG_WARNING;
            case LogLevel::NOTICE:
                return LOG_NOTICE;
            case LogLevel::INFO:
                return LOG_INFO;
            case LogLevel::DEBUG:
                return LOG_DEBUG;
            default:
                throw new RuntimeException('unknown log level');
        }
    }
518523
public void debug(final String message, final int level) {
        messages.add(new LogMessage(message, LogMessage.Type.DEBUG, level));
        log.debug(message);
    }
42095
private function output($text, $level = null)
    {
        if ($this->logger) {
            $this->logger->log($level ?: LogLevel::DEBUG, $text);
        }

        if ($this->debug) {
            fwrite(STDERR, sprintf('xdebug-handler[%d] %s', getmypid(), $text.PHP_EOL));
        }
    }
1292123
public function setLogLevel($level= xPDO::LOG_LEVEL_FATAL) {
        $oldLevel = $this->logLevel;
        $this->logLevel= intval($level);
        return $oldLevel;
    }
363143
public function checkLevel($level)
    {
        if (static::$levels === null) {
            // Psr\Log does not provide Enum, so we need to load levels from LogLevel constants
            $reflection = new \ReflectionClass(LogLevel::class);
            static::$levels = $reflection->getConstants();
        }

        if (!in_array($level, static::$levels)) {
            $levels = implode(', ', static::$levels);
            throw new InvalidArgumentException("Level must be one of [$levels].");
        }
    }