MyQEE\Server\Server::log PHP 메소드

log() 공개 메소드

输出自定义log
public log ( string $label, array $data = null, string $type = 'other', string $color = '[36m' )
$label string
$data array
$type string
$color string
    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 = "";
        $str = $beg . '[' . date("Y-m-d H:i:s", $t) . "{$f}][{$type}]{$end} - " . ($label ? "{$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;
        }
    }