This example describes the usage of logging in thinkphp project development. Share to everyone for your reference. The specific methods are as follows:
1, the establishment of the log table
Copy Code code as follows:
CREATE TABLE ' Logs ' (
' id ' int (one) not NULL auto_increment,
' GUID ' varchar (m) Character set UTF8 not NULL,
' Addtime ' timestamp not NULL default Current_timestamp,
' Account ' varchar (m) Character set UTF8 not NULL,
' Nickname ' varchar (m) Character set UTF8 not NULL,
' app ' varchar character set UTF8 not NULL,
' Action ' varchar (m) Character set UTF8 not NULL,
' method ' varchar (m) Character set UTF8 not NULL,
' Query_string ' text character set UTF8 not NULL,
' Is_desc ' varchar (m) Character set UTF8 not NULL,
' desc ' varchar (m) Character set UTF8 not NULL,
' ipaddr ' varchar (m) Character set UTF8 not NULL,
' Unique_flag ' varchar (m) Character set UTF8 not NULL,
PRIMARY KEY (' id ')
) Engine=innodb DEFAULT Charset=utf8;
2, common/common.php inside the definition of the method:
Copy Code code as follows:
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 ')];
}
Call Addoperationlog () in other action classes;
I hope this article will be helpful to everyone's thinkphp framework program design.