Personal gadget mylog upgrade version

<?php
    /**
	* Unicode to Chinese
	*/
	function replace_unicode_escape_sequence($match) {
	  return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
	}
	

	/**
	* $params data source to output
	* $filename The file name to be output, automatically append the time after the file name 	
	* $filepath the file path to output,
	* If it is in liunx, please give the corresponding "file path" read and write permissions. As default in the default value,
	* Command: chmod -R 777 default
	* Usage: echolog($params, 'test');  
	* Note: Appending data to the same file is currently not supported. Other methods will be provided later
	*/
	function echolog($params, $filename='log', $filepath='/home/wwwroot/default/')
	{
		if (!$params) {
			return;
		}

		if (is_array($params)) {
			$reult = json_encode($params);
		}
		else
		{
			$reult = json_encode(array($params));
		}
		// Call Unicode to Chinese
		$reult = preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $reult);
		
		$filepath .= $filename.'_'.date("Ymd").'.txt';

		file_put_contents($filepath, date("Y_m_d H:i:s").'   '.$reult.PHP_EOL, FILE_APPEND);
	}

?>


Introduce mylog.php into the project and you can use it. How to use:
echolog(data source,'file name','file path');



If there are any shortcomings, please leave a message for guidance

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326517760&siteId=291194637