1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60:
<?php
namespace CzProject\Logger;
class CliLogger implements ILogger
{
private $level;
private $colored;
protected static $colors = array(
ILogger::SUCCESS => '0;32',
ILogger::ERROR => '0;31',
ILogger::EXCEPTION => '0;31',
ILogger::CRITICAL => '0;31',
ILogger::WARNING => '0;33',
ILogger::DEBUG => '1;30',
);
public function __construct($level = ILogger::INFO, $colored = NULL)
{
$this->level = $level;
$this->colored = $colored !== NULL ? $colored : self::detectColoredOutput();
}
public function log($msg, $level = ILogger::INFO)
{
if ($level >= $this->level) {
if ($this->colored && isset(self::$colors[$level])) {
echo "\033[", self::$colors[$level], 'm', $msg, "\033[0m\n";
} else {
echo $msg, "\n";
}
}
}
public static function detectColoredOutput()
{
return (getenv('ConEmuANSI') === 'ON'
|| getenv('ANSICON') !== FALSE
|| (defined('STDOUT') && function_exists('posix_isatty') && posix_isatty(STDOUT)));
}
}