The method of printing front-end parameters in TP5

In the development model where the front-end and the back-end are separated, the back-end receives the front-end parameters and prints the parameters from time to time. I often return, such as

	$vv = input('param.'); //获取全部参数
	return json_encode(array('status'=>'200','msg'=>$vv));

Print as shown

There is also a second method, which is to print to the back-end file for easy recording and viewing. The common printing method is written in common.php:

//测试输入数据
function lq_test($data) {
    $time=gmdate("Y-m-d H:i:s",time()+8*3600);
	file_put_contents("test____txt.txt","------------------$time start------------------\r\n".var_export($data,true)."\r\n\r\n------------------$time end------------------\r\n\r\n\r\n\r\n",FILE_APPEND);
}

 You can see that the file is generated in the directory, open it:

------------------2020-11-11 11:15:53 start------------------
array (
  'wxapp_id' => '10002',
  'token' => '53c5a0b0d7714fcf016c88b2f704967c',
)

------------------2020-11-11 11:15:53 end------------------

 

 

The following is the method of writing logs in the TP framework:

public function logs(){
    $str = "我是一个字符串";
    $this->logger($str);
}
/* 定义logger来写日志 */
private function logger($content){
    $logSize = 100000; //日志大小
    // $log = "log.txt";
    $log = "./logger/log.txt";
    if(file_exists($log) && filesize($log) > $logSize){
        unlink($log);
    }
    // linux的换行是 \n  windows是 \r\n
    // FILE_APPEND 不写第三个参数默认是覆盖,写的话是追加 
    file_put_contents($log,date('H:i:s')."\n".$content."\n",FILE_APPEND);
}

 $log is used to define the path of the log. $log = "log.txt"; The location where the log.txt file is stored is: the root directory (the same level as the index.php entry file). The reason is: the entry of the project is index.php, which is equivalent to doing it in the entry file load.

But usually defined log: stored in the log directory

See some good posts to share about this issue: https://www.cnblogs.com/lty-fly/p/11907356.html

https://zhuanlan.zhihu.com/p/148593818

Guess you like

Origin blog.csdn.net/EasyTure/article/details/109615165