/** * 写入日志 * * @param string $strFileName * @param string $strType * @param string $strMSG * @param string $strExtra * @param string $line */ public static function out($strFileName = "", $strType = "I", $strMSG = "", $strExtra = "", $line = "") { if ($strType == "") { $strType = "I"; } if (!is_writable(self::$logpath)) { @chmod(self::$logpath, 0777); } $logfile = rtrim(self::$logpath, '/') . '/' . $strFileName . '_' . date("ymd") . '.log'; if (file_exists($logfile) && !is_writable($logfile)) { @chmod($logfile, 0644); } $handle = @fopen($logfile, "a+"); if ($handle) { // 判断是否CLI if (isset($_SERVER['SHELL']) && !isset($_SERVER['HTTP_HOST'])) { $arg = ""; if ($_SERVER['argc'] > 0) { $arg = " ARGV:" . json_encode($_SERVER['argv']); } $strContent = "[" . date("Y-m-d H:i:s") . "] [" . strtoupper($strType) . "] [CLI] MSG:[" . $strMSG . "]" . $strExtra . " Location:" . $_SERVER["SCRIPT_FILENAME"] . $arg . ($line ? " Line:" . $line : "") . "\n"; } else { $strContent = "[" . date("Y-m-d H:i:s") . "] [" . strtoupper($strType) . "] [" . Sys_Tools::getRemoteAddr() . "] MSG:[" . $strMSG . "]" . $strExtra . " Location:" . $_SERVER["SCRIPT_FILENAME"] . ($line ? " Line:" . $line : "") . " QUERY_STRING:" . $_SERVER["QUERY_STRING"] . " HTTP_REFERER:" . (isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : "") . " User-Agent:" . $_SERVER["HTTP_USER_AGENT"] . "\n"; } if (!fwrite($handle, $strContent)) { @fclose($handle); die("Write permission deny"); } @fclose($handle); } }