public function log($label, array $data = null, $type = 'other', $color = '[36m')
{
if (!isset(self::$logPath[$type])) {
return;
}
if (null === $data) {
$data = $label;
$label = null;
}
list($f, $t) = explode(' ', microtime());
$f = substr($f, 1, 4);
$beg = "{$color}";
$end = "[39m";
$str = $beg . '[' . date("Y-m-d H:i:s", $t) . "{$f}][{$type}]{$end} - " . ($label ? "[37m{$label}{$end} - " : '') . (is_array($data) ? json_encode($data, JSON_UNESCAPED_UNICODE) : $data) . "\n";
if (is_string(self::$logPath[$type])) {
# 写文件
@file_put_contents(self::$logPath[$type], $str, FILE_APPEND);
} else {
# 直接输出
echo $str;
}
}