开发人员主动写文本日志
@param string $file 日志文件名
@param mixed $msg 要记录的内容
@param $raw bool 是否以原始格式进行记录,否则会加些附加信息
195551
public function writeLog(string $file, $msg, bool $raw = false): void
    {
        //是否允许记录开发人员日志
        configDefault(false, 'log', 'writeLog') ? $this->log($file, $msg, $raw) : null;
    }
612972
public static function lastErrorMsg($file,$message,$data) {
		Console::writeLine(PHP_EOL."<error>The JSON file, ".$file.", wasn't loaded. The error: ".$message."</error>");
		if ($message == "Syntax error, malformed JSON") {
			Console::writeLine("");
			$parser = new JsonLint\JsonParser();
			$error  = $parser->lint($data);
			Console::writeError($error->getMessage(), false, true);
		}
	}
1025126
public static function logInfo($msg, $mod = null, $file = 0, $line = 0)
    {
        $LOG = array('type' => 'INFO',
            'message' => (!is_null($msg) ? $msg : ''),
            'logFile' => (!is_null($file) ? $file : ''),
            'logLine' => (!is_null($line) ? $line : ''),
            'context' => (!is_null($mod) ? $mod : ''),
            'runtime' => round(self::getRelativeTime(), 4),);

        self::$Logs[] = $LOG;
    }
972496
public function uploadFile(File $file, $raw_file)
    {
        $result = new Result();

        if (file_exists($raw_file)) {
            return $this->uploadFileFromFilesystem($file, $raw_file);
        }

        return $result;
    }
973361
public static function checkLength($field, $length, $msg)
    {
        if ((StringUtils::isEmpty($field) === false) && mb_strlen($field) != $length) {
            throw new MsgException($msg);
        }
    }
1130542
public static function log(string $msg, array $data = [], int $level = self::VERB_DEBUG, array $opts = []): void
    {
        $levelName  = self::LEVEL_NAMES[$level] ?? 'INFO';
        $colorName  = self::LEVEL2TAG[$level] ?? 'info';
        $taggedName = ColorTag::add($levelName, $colorName);

        $userOpts = [];
        foreach ($opts as $n => $v) {
            if (\is_numeric($n) || \strpos($n, '_') === 0) {
                $userOpts[] = "[$v]";
            } else {
                $userOpts[] = "[$n:$v]";
            }
        }

        $optString = $userOpts ? ' ' . \implode(' ', $userOpts) : '';

        self::write(\sprintf(
            '%s [%s]%s %s %s',
            \date('Y/m/d H:i:s'),
            $taggedName,
            $optString,
            \trim($msg),
            $data ? \PHP_EOL . \json_encode($data, \JSON_UNESCAPED_SLASHES | \JSON_PRETTY_PRINT) : ''
        ));
    }
593804
public function rmFile($file)
    {

        if (!is_file($file)) {
            $this->errorMsg = "this is not a file";
            return false;
        }
        if (unlink($file)) {
            return true;
        } else {
            $this->errorMsg = "fail to remove the file!";
            return false;
        }
    }
564066
private static function _writeLog($filename, $msg, $addTime = true)
    {
        // preppend details
        if($addTime) {
            $msg = self::formatHeaderWithTime() . $msg;
        }

        if(DI::has('BufferOptions')) {

            $options = DI::get('BufferConnectionOptions');

            $callback = function($data) use ($filename) {
                Writer::writeLogVerbose($filename, implode("\n\n", $data) . "\n\n");
            };

            // just to be on safe side, set max size to 500, that is reasonable number
            $maxSize = 500;

            $size = isset($options['size']) && is_int($options['size']) && $options['size'] > 0 && $options['size'] < $maxSize
                ? $options['size']
                : $maxSize;

            $buffer = new Buffer($filename, Buffer::ADAPTER_REDIS, $size, $callback, $options);
            $buffer->add($msg);

        } else {
            Writer::writeLogVerbose($filename, $msg);
        }
    }
231166
private function _log($group, $level, $message, array $context = array())
    {
        if (!$this->options['enabled']) return false;
        
        $initLevel = strtoupper($this->options['level']);
        $optionLevelNum = isset(static::$levels[$initLevel]) ? static::$levels[$initLevel] : 400;
        
        $currentLevelNum = static::$levels[strtoupper($level)];
        
        /**
         * 当写入级别大于配置级别时才进行记录
         * 比如，配置级别为 Error，则调用 warning(), notice() 等不会进行记录
         */
        if ($currentLevelNum >= $optionLevelNum) {
            if (!static::$timezone) {
                static::$timezone = new \DateTimeZone(date_default_timezone_get() ?: 'PRC');
            }
            //$date = \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), static::$timezone)->setTimezone(static::$timezone);
            //var_dump($date); exit;
            
            // 日志级别
            $level = strtolower($level);
            
            // 日志文件后缀，只对文件方式有效
            $file_ext = trim($this->getOption('file_ext'), '.');
            if (($pos = strrpos($file_ext, '.')) !== false) {
                $file_ext = substr($file_ext, $pos + 1);
            }
            $this->setOption('file_ext', $file_ext);
            
            // 日志内容
            $record = array(
                'datetime'  => date("Ymd H:i:s"),
                'level'     => $level,
                'message'   => $this->formatMessage($message),
                'context'   => $context
            );
            
            // key
            if (!($key = $this->getOption('file'))) {
                $key = date('Ymd');
            }
            
            // path: group_name/error/20161012.error.log
            $key = ($group ? $group . '/' : '') . $level . '/' . $key . '.' . $level;
            
            //$this->append($key, str_repeat('-', 50));
            return $this->append($key, $record);
        } else {
            return false;
        }
    }
12981
public function verbose($msg, $fileHandle = null)
    {
        $this->log(self::$logLevelVerbose, $msg, $fileHandle = null);
    }
1373246
public function rawLog(string $type = '', string $message = '', ?string $source = null, ?string $excp = null): bool
    {
        $src = $source !== null
            ? \sprintf('[%s] ', \is_object($source) ? '\\'.\get_class($source) : (string)$source)
            : '';
        $exc = $excp !== null && ($excp instanceof \Exception) ? \sprintf('[Ex: %s] ', $excp->getMessage()) : '';
        $exc = \str_replace(["\r", "\n", "\t"], '', $exc);
        $msg = \sprintf('%s %s %s%s%s%s', \date('d-m-Y H:i:s'), $type, $src, $exc, $message, Tags::CRLF);

        return File::append($this->logFile, $msg);
    }
1152358
protected function createLogsFile($file)
    {
        $directory = dirname($file);

        // Create directory
        if (!$this->files->isDirectory($directory)) {
            $this->files->createDir($directory);
        }

        // Create file
        if (!$this->files->has($file)) {
            $this->files->put($file, '');
        }
    }
171433
public function log($producer, $msg, $object = false) {
        if(!($this->acceptedProducers & $producer)) { return; }

        $msgFmt = self::format($msg, $this->processId, $this->time, $this->flags);
        if($object) {
            $msgFmt .= " " . json_encode($object);
        }
        $this->logRaw($msgFmt);
    }
1363048
def msg(message, *args, **kwargs):
    """"""
    global log_file
    if log_file is None:
        log_file = sys.stderr
    if long_msg:
        file_name, line = caller_trace()
        file_name, file_type = os.path.splitext(file_name)
        if file_name.endswith('/__init__'):
            file_name = os.path.basename(os.path.dirname(file_name))
        elif file_name.endswith('/__main__'):
            file_name = "(-m) {0}".format(
                os.path.basename(os.path.dirname(file_name)))
        else:
            file_name = os.path.basename(file_name)
        head = '{0}{1} ({2}): '.format(file_name, file_type, line)
    else:
        head = '[SERVER] '
    out = StringIO()
    for line in message.format(*args, **kwargs).split('\n'):
        out.write('{0}{1}\n'.format(head, line))
    out.flush()
    out.seek(0)
    if _msg_stderr:
        sys.stderr.write(out.read())
        sys.stderr.flush()
    else:
        log_file.write(out.read())
        log_file.flush()
    out.close()
1024637
public function log($msg, $timestamp = true)
    {
        if ($timestamp) {
            $timestamp = strftime("%Y-%m-%d %H:%M:%S");
            $msg = "[{$timestamp}] {$msg}";
        }
        $this->addResult($msg);
        if ($this->verbose) echo $msg . PHP_EOL;
    }
590519
private function _writeLog($msg) {
        $log = "-------------------------------------\n";
        $log .= date('Y-m-d H:i:s') . ":\n";
        $log .= $msg."\n";
        $log .= "-------------------------------------\n";
        file_put_contents($this->_output, $log, FILE_APPEND | LOCK_EX);
    }
1226485
protected function tryLog($msg, $tries = 0)
    {
        if ((bool)@fwrite($this->stream, $msg))
            return;

        if (0 < $tries)
        {
            trigger_error(sprintf('%s - Unable to log message: "%s"', get_called_class(), $tries, $msg));
            return;
        }

        $this->attemptStreamRecovery();

        $this->tryLog($msg, ++$tries);
    }