本文实例讲述了THINKPHP项目开发中的日志记录用法。分享给大家供大家参考。具体方法如下:
1、建立日志表
function addOperationLog($desc=NULL,$unique_flag='system',$app=APP_NAME,$action=MODULE_NAME,$method=ACTION_NAME) {
$global_skype_db_config = getGlobalSkypeLogDbConfig();
static $global_skype_log_db_conn;
if (!$global_skype_log_db_conn) {
$global_skype_log_db_conn = MysqL_connect($global_skype_db_config['hostname'],$global_skype_db_config['username'],$global_skype_db_config['password']);
}
if (!$global_skype_log_db_conn) {
die('MysqL_Error:' . FILE . '|' . LINE . '|' . MysqL_error());
}
MysqL_query('use ' . $global_skype_db_config['database'],$global_skype_log_db_conn);
MysqL_query('set names utf8 ',$global_skype_log_db_conn);
$account = getAdminAccount();
$nickname = getAdminNickname();
$user_id = getAdminUserId();
$ipaddr = get_client_ip();
$query_string = print_r(array_merge($_GET,$_POST),true);
$desc = $desc;
$is_desc = 0;
$unique_flag = $unique_flag;
if ($desc) {
$is_desc = 1;
}
$insert_time = date('Y-m-d H:i:s');
$query = "INSERT INTO " . C('LOG_DB_TABLE') . "
(guid
,account
,nickname
,addtime
,app
,action
,
method
,query_string
,is_desc
,desc
,ipaddr
,unique_flag
) VALUES ('$user_id','$account','$nickname','$insert_time','$app',
'$action','$method','$query_string','$is_desc','$desc','$ipaddr','$unique_flag');";
return MysqL_query($query,$global_skype_log_db_conn);
}
function getAdminAccount() {
return $_SESSION['loginAccount'];
}
function getAdminNickname() {
return $_SESSION['loginUserName'];
}
function getAdminUserId() {
return $_SESSION[C('USER_AUTH_KEY')];
}
在其他操作类里调用addOperationLog();即可
希望本文所述对大家的ThinkPHP框架程序设计有所帮助。
原文链接:https://www.f2er.com/thinkphp/23222.html