THINKPHP项目开发中的日志记录实例分析
程序员文章站
2023-03-26 11:12:15
本文实例讲述了thinkphp项目开发中的日志记录用法。分享给大家供大家参考。具体方法如下:
1、建立日志表
复制代码 代码如下:create table `logs`...
本文实例讲述了thinkphp项目开发中的日志记录用法。分享给大家供大家参考。具体方法如下:
1、建立日志表
复制代码 代码如下:
create table `logs` (
`id` int(11) not null auto_increment,
`guid` varchar(100) character set utf8 not null,
`addtime` timestamp not null default current_timestamp,
`account` varchar(100) character set utf8 not null,
`nickname` varchar(100) character set utf8 not null,
`app` varchar(100) character set utf8 not null,
`action` varchar(100) character set utf8 not null,
`method` varchar(100) character set utf8 not null,
`query_string` text character set utf8 not null,
`is_desc` varchar(100) character set utf8 not null,
`desc` varchar(100) character set utf8 not null,
`ipaddr` varchar(100) character set utf8 not null,
`unique_flag` varchar(100) character set utf8 not null,
primary key (`id`)
) engine=innodb default charset=utf8 ;
`id` int(11) not null auto_increment,
`guid` varchar(100) character set utf8 not null,
`addtime` timestamp not null default current_timestamp,
`account` varchar(100) character set utf8 not null,
`nickname` varchar(100) character set utf8 not null,
`app` varchar(100) character set utf8 not null,
`action` varchar(100) character set utf8 not null,
`method` varchar(100) character set utf8 not null,
`query_string` text character set utf8 not null,
`is_desc` varchar(100) character set utf8 not null,
`desc` varchar(100) character set utf8 not null,
`ipaddr` varchar(100) character set utf8 not null,
`unique_flag` varchar(100) character set utf8 not null,
primary key (`id`)
) engine=innodb default charset=utf8 ;
2、common/common.php里面进行方法的定义:
复制代码 代码如下:
function getglobalskypelogdbconfig() {
$global_skype_db_config = array(
'dbms' => c('db_type'),
'username' => c('db_user'),
'password' => c('db_pwd'),
'hostname' => c('db_host'),
'database' => c('db_name'),
);
return $global_skype_db_config;
}
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')];
}
$global_skype_db_config = array(
'dbms' => c('db_type'),
'username' => c('db_user'),
'password' => c('db_pwd'),
'hostname' => c('db_host'),
'database' => c('db_name'),
);
return $global_skype_db_config;
}
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框架程序设计有所帮助。
推荐阅读
-
Java开发项目实例中的技术总结
-
C#中异步编程4async与await异步程序开发的实例分析
-
ThinkPHP中__initialize()和类的构造函数__construct()用法分析_php实例
-
Django项目开发中cookies和session的常用操作分析
-
thinkPHP中钩子的使用方法实例分析
-
THINKPHP项目开发中的日志记录实例分析
-
Django项目开发中cookies和session的常用操作分析
-
python中scrapy处理项目数据的实例分析
-
ThinkPHP中__initialize()和类的构造函数__construct()用法分析_php实例
-
thinkPHP中钩子的使用方法实例分析