|
|
|
@ -40,15 +40,23 @@
|
|
|
|
|
/**
|
|
|
|
|
* Terminal escape sequence to clear formatting.
|
|
|
|
|
*/
|
|
|
|
|
const COLOR_RESET = "\033[0m";
|
|
|
|
|
private const COLOR_RESET = "\033[0m";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the color marker for the given logging verbosity.
|
|
|
|
|
* Specifies whether to enable terminal colors.
|
|
|
|
|
*/
|
|
|
|
|
public static bool $showColor = true;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the color marker for the given logging verbosity if colors are enabled.
|
|
|
|
|
* @param int $verbosity Logging verbosity to used for printing.
|
|
|
|
|
* @return ?string Terminal escape sequence to color foreground text.
|
|
|
|
|
*/
|
|
|
|
|
static function getVerbosityColorMarker(int $verbosity): ?string {
|
|
|
|
|
// See https://en.wikipedia.org/wiki/ANSI_escape_code#Colors for reference.
|
|
|
|
|
if (!LoggingVerbosity::$showColor) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
return match($verbosity) {
|
|
|
|
|
LoggingVerbosity::Error => "\033[31m",
|
|
|
|
|
LoggingVerbosity::Warning => "\033[93m",
|
|
|
|
@ -57,6 +65,16 @@
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return ?string Terminal escape sequence to turn off color if colors are enabled.
|
|
|
|
|
*/
|
|
|
|
|
static function getColorResetMarker(): ?string {
|
|
|
|
|
if (!LoggingVerbosity::$showColor) {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
return LoggingVerbosity::COLOR_RESET;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns a pair of optíons trigerring the given verbosity.
|
|
|
|
|
* @param int $verbosity Logging verbosity to set using flag.
|
|
|
|
@ -101,7 +119,7 @@
|
|
|
|
|
$runtime = runtime_str();
|
|
|
|
|
$marker = LoggingVerbosity::getVerbosityMarker($message_verbosity);
|
|
|
|
|
$color_marker = LoggingVerbosity::getVerbosityColorMarker($message_verbosity);
|
|
|
|
|
$color_reset = LoggingVerbosity::COLOR_RESET;
|
|
|
|
|
$color_reset = LoggingVerbosity::getColorResetMarker();
|
|
|
|
|
// Need to concatenate marker to avoid interpolated array member syntax.
|
|
|
|
|
fwrite(STDERR, $color_marker . "[$runtime] [$marker] $msg$color_reset" . PHP_EOL);
|
|
|
|
|
}
|
|
|
|
|