Browse Source

update: enhance log output

master
dnomd343 2 years ago
parent
commit
e8d0d56b8e
  1. 15
      src/Logger.php

15
src/Logger.php

@ -17,6 +17,13 @@ class logging {
public const ERROR = 3; public const ERROR = 3;
public const CRITICAL = 4; public const CRITICAL = 4;
public static int $logLevel; public static int $logLevel;
private static array $logName = array(
logging::DEBUG => 'DEBUG',
logging::INFO => 'INFO',
logging::WARNING => 'WARNING',
logging::ERROR => 'ERROR',
logging::CRITICAL => 'CRITICAL',
);
public static function debug($message): void { public static function debug($message): void {
logging::output($message, logging::DEBUG); // debug level logging::output($message, logging::DEBUG); // debug level
@ -38,11 +45,13 @@ class logging {
logging::output($message, logging::CRITICAL); // critical level logging::output($message, logging::CRITICAL); // critical level
} }
private static function output($message, $type): void { private static function output($message, $logType): void {
global $logColor; global $logColor;
if ($type < logging::$logLevel) { if ($logType < logging::$logLevel) {
return; // skip output return; // skip output
} }
echo "\033[" . $logColor[$type] . $message . "\033[0m" . PHP_EOL; $timeStr = '[' . date('Y-m-d H:i:s', time()) . ']';
$message = $timeStr . ' [' . logging::$logName[$logType] . '] ' . $message;
echo "\033[" . $logColor[$logType] . $message . "\033[0m" . PHP_EOL;
} }
} }

Loading…
Cancel
Save