php创建日志

public function mkDirs($dir, $content, $type = '1')
{

    if ($type == 1) {
        $dir = $_SERVER['DOCUMENT_ROOT'] . '/runtime/' . $dir . '/data/' . date('Y/m/d', time());
    } else {
        $dir = $_SERVER['DOCUMENT_ROOT'] . '/runtime/' . $dir . '/error/' . date('Y/m/d', time());
    }
    $file = $dir.'/'.date('Y-m-d-H', time()) . '.log';
    if (!is_dir($dir)) {
        exec("mkdir $dir -p");
    }
    if (file_exists($file)) {
        file_put_contents($file, $content.PHP_EOL, FILE_APPEND);
    } else {
        file_put_contents($file, $content.PHP_EOL, FILE_APPEND);
    }
    return true;
}
0 Comments
Leave a Reply