COLORS!!!! (and custom logging callbacks
This commit is contained in:
parent
4a6335a8b2
commit
c1fd3c4ea7
@ -17,6 +17,70 @@ namespace danog\MadelineProto;
|
||||
|
||||
class Logger
|
||||
{
|
||||
const foreground = array(
|
||||
'default' => 39,
|
||||
|
||||
'black' => 30,
|
||||
'red' => 31,
|
||||
'green' => 32,
|
||||
'yellow' => 33,
|
||||
'blue' => 34,
|
||||
'magenta' => 35,
|
||||
'cyan' => 36,
|
||||
'light_gray' => 37,
|
||||
|
||||
'dark_gray' => 90,
|
||||
'light_red' => 91,
|
||||
'light_green' => 92,
|
||||
'light_yellow' => 93,
|
||||
'light_blue' => 94,
|
||||
'light_magenta' => 95,
|
||||
'light_cyan' => 96,
|
||||
'white' => 97,
|
||||
);
|
||||
|
||||
const background = array(
|
||||
'default' => 49,
|
||||
|
||||
'black' => 40,
|
||||
'red' => 41,
|
||||
'magenta' => 45,
|
||||
'yellow' => 43,
|
||||
'green' => 42,
|
||||
'blue' => 44,
|
||||
'cyan' => 46,
|
||||
'light_gray' => 47,
|
||||
|
||||
|
||||
'dark_gray' => 100,
|
||||
'light_red' => 101,
|
||||
'light_green' => 102,
|
||||
'light_yellow' => 103,
|
||||
'light_blue' => 104,
|
||||
'light_magenta' => 105,
|
||||
'light_cyan' => 106,
|
||||
'white' => 107,
|
||||
);
|
||||
|
||||
const set = [
|
||||
'bold' => 1,
|
||||
'dim' => 2,
|
||||
'underlined' => 3,
|
||||
'blink' => 4,
|
||||
'reverse' => 5,
|
||||
'hidden' => 6,
|
||||
];
|
||||
|
||||
const reset = [
|
||||
'all' => 0,
|
||||
'bold' => 21,
|
||||
'dim' => 22,
|
||||
'underlined' => 24,
|
||||
'blink' => 25,
|
||||
'reverse' => 26,
|
||||
'hidden' => 28,
|
||||
];
|
||||
|
||||
public static $storage = [];
|
||||
public static $mode = null;
|
||||
public static $optional = null;
|
||||
@ -26,6 +90,7 @@ class Logger
|
||||
public static $has_thread = false;
|
||||
public static $BIG_ENDIAN = false;
|
||||
public static $bigint = true;
|
||||
public static $colors = [];
|
||||
|
||||
const ULTRA_VERBOSE = 5;
|
||||
const VERBOSE = 4;
|
||||
@ -42,6 +107,12 @@ class Logger
|
||||
if (class_exists('\danog\MadelineProto\VoIP')) {
|
||||
\Threaded::extend('\danog\MadelineProto\VoIP');
|
||||
}
|
||||
self::$colors[self::ULTRA_VERBOSE] = implode(';', [self::foreground['light_gray'], self::set['dim']]);
|
||||
self::$colors[self::VERBOSE] = implode(';', [self::foreground['green'], self::set['bold']]);
|
||||
self::$colors[self::NOTICE] = implode(';', [self::foreground['yellow']]);
|
||||
self::$colors[self::WARNING] = implode(';', [self::foreground['white'], self::set['dim'], self::background['red']]);
|
||||
self::$colors[self::ERROR] = implode(';', [self::foreground['white'], self::set['bold'], self::background['red']]);
|
||||
self::$colors[self::FATAL_ERROR] = implode(';', [self::foreground['red'], self::set['bold'], self::background['light_gray']]);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -67,6 +138,9 @@ class Logger
|
||||
|
||||
public static function log($params, $level = self::NOTICE)
|
||||
{
|
||||
if (self::$mode === 4) {
|
||||
return self::$optional(is_array($params) ? $params : [$params], $level);
|
||||
}
|
||||
if ($level > self::$level) {
|
||||
return false;
|
||||
}
|
||||
@ -90,7 +164,7 @@ class Logger
|
||||
error_log($param.PHP_EOL, 3, self::$optional);
|
||||
break;
|
||||
case 3:
|
||||
echo $param.PHP_EOL;
|
||||
echo "\033[" . self::$colors[$level] . "m" . $param . "\033[0m".PHP_EOL;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -492,6 +492,8 @@ class MTProto extends \Volatile
|
||||
* 1 - Log to the default logger destination
|
||||
* 2 - Log to file defined in second parameter
|
||||
* 3 - Echo logs
|
||||
* 4 - Call callable provided in logger_param. logger_param must accept two parameters: array $message, int $level
|
||||
* $message is an array containing the messages the log, $level, is the logging level
|
||||
*/
|
||||
'logger' => 1, // write to
|
||||
'logger_param' => '/tmp/MadelineProto.log',
|
||||
|
@ -23,6 +23,13 @@ try {
|
||||
} catch (\danog\MadelineProto\Exception $e) {
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
\danog\MadelineProto\Logger::log(['hey'], \danog\MadelineProto\Logger::ULTRA_VERBOSE);
|
||||
\danog\MadelineProto\Logger::log(['hey'], \danog\MadelineProto\Logger::VERBOSE);
|
||||
\danog\MadelineProto\Logger::log(['hey'], \danog\MadelineProto\Logger::NOTICE);
|
||||
\danog\MadelineProto\Logger::log(['hey'], \danog\MadelineProto\Logger::WARNING);
|
||||
\danog\MadelineProto\Logger::log(['hey'], \danog\MadelineProto\Logger::ERROR);
|
||||
\danog\MadelineProto\Logger::log(['hey'], \danog\MadelineProto\Logger::FATAL_ERROR);
|
||||
|
||||
if (file_exists('.env')) {
|
||||
echo 'Loading .env...'.PHP_EOL;
|
||||
$dotenv = new Dotenv\Dotenv(getcwd());
|
||||
|
Loading…
x
Reference in New Issue
Block a user