Get the App
SLTechnology News&Howtos  ›  Development  › 

How to write logging in THINKPHP project development

Shulou Source: shulou.com Published: 2022-06-03 09:08:54 10月18日 Update

This article focuses on "how to write log records in THINKPHP project development". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to write log records in THINKPHP project development.

The specific methods are as follows:

1. Set up a log table

The copy code is as follows:

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

`roomt` 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

`varchar (is_) character set utf8 NOT NULL

`room`varchar (100) character set utf8 NOT NULL

`ipaddr` varchar (100) character set utf8 NOT NULL

`varchar (unique_) character set utf8 NOT NULL

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8

2. Define the method in Common/common.php:

The copy code is 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 Hrigi')

$query = "INSERT INTO `". C ('LOG_DB_TABLE'). "`(`guid`, `nickt`, `nickname`, `addtime`, `app`, `action`)

`method`, `query_ string`, `is_ string`, `room`, `ipaddr`, `unique_ string`) 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 operation classes; you can

At this point, I believe you have a deeper understanding of "how to write logging in THINKPHP project development". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Logs code projects project development development methods content learning practical deeper interest practical practical easy to operate more friends websites channels inquiries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn MariaDB Redmi Shulou Tech Info NVidia