方式一

/**
     * 日志输出
     * @param $contents
     */
    public function writeLog($contents)
    {
        $file = __DIR__ . '/../../runtime/timer/timer_' . date('y-m-d') . '.log';
        if (!is_file($file)) {
            // 如果文件不存在,则创建一个新文件。
            file_put_contents($file, '', FILE_APPEND);
        }

        if (!is_string($contents)) {
            $contents = date('Y-m-d H:i:s') . ':' . json_encode($contents, JSON_UNESCAPED_UNICODE) . "\r\n";
        } else {
            $contents = date('Y-m-d H:i:s') . ':' . $contents . "\r\n";
        }

        file_put_contents($file, $contents, FILE_APPEND);
    }

方式二

$now      = date('y-m-d', time());
$filename = 'log/tongbu_' . $now . '.log';
$file     = fopen($filename, "a+");   //a+表示文件可读写方式打开
fwrite($file, '开始写入' . "\n");
$time   = time();
$res    = "www.axinblog.com";
$result = 'ok';
fwrite($file, $time . "\t" . $res . "\t" . $result . "\n");
fwrite($file, '写入完成' . "\n");

方式三

public function writeLog($contents)
{
    $now      = date('y-m-d', time());
    $filename = 'log/tongbu_' . $now . '.log';
    $time     = time();
    $re       = "www.axinblog.com";
    $result   = 'ok';
    error_log($time . "\t" . $re . "\t" . $result . "\n", 3, $filename);// 3表示消息被发送到后面的文件
}