tp3.2 写入日志
function logs($content, $subDir = ''){ $subDir = trim($subDir, '/\\'); if (empty($content)) return false; static $arrConfig = array(); if (empty($arrConfig)){ $arrPath = array(MODULE_NAME, CONTROLLER_NAME, ACTION_NAME); $arrConfig['root_path'] = './Runtime/Logs/'; $arrConfig['sub_dir'] = implode('/', $arrPath); $arrConfig['file_name'] = '/' . date('Ymd') . '.log'; $arrConfig['client_ip'] = get_client_ip(); $arrConfig['logs_no'] = date('ymdHis') . microtime() * 1000000; } $filepath = $arrConfig['root_path']; if ($subDir){ $filepath .= $subDir ; } else { $filepath .= $arrConfig['sub_dir'] ; } if (!file_exists($filepath)){ mkdir($filepath, 0777, TRUE); } $filepath .= $arrConfig['file_name']; $header = sprintf("\r\n\r\n[%s][%s][%s] ", date('Y-m-d H:i:s'), $arrConfig['client_ip'],$arrConfig['logs_no']); @file_put_contents($filepath, $header . $content, FILE_APPEND); return $arrConfig['logs_no'] ; }