Php log recording method based on custom functions, php function log
This example describes how php Records log based on user-defined functions. We will share this with you for your reference. The details are as follows:
/*** Record Error Log ** @ param log Content $ res */function save_log ($ res) {$ err_date = date ("Ym", time ()); // $ address = '/var/log/error'; $ address = '. /error '; if (! Is_dir ($ address) {mkdir ($ address, 0700, true);} $ address = $ address. '/'. $ err_date. '_ error. log'; $ error_date = date ("Y-m-d H: I: s", time (); if (! Empty ($ _ SERVER ['HTTP _ referer']) {$ file = $ _ SERVER ['HTTP _ referer'];} else {$ file = $ _ SERVER ['request _ URI '];} if (is_array ($ res) {$ res_real = "$ error_date \ t $ file \ n "; error_log ($ res_real, 3, $ address); $ res = var_export ($ res, true); $ res = $ res. "\ n"; error_log ($ res, 3, $ address);} else {$ res_real = "$ error_date \ t $ file \ t $ res \ n "; error_log ($ res_real, 3, $ address );}}
var_export()
Detailed solution:
Var_export-String Representation of the output or returned variable
Description:
mixed var_export ( mixed expression , bool )
This function returns the structure information about the variables passed to this function. It is similar to var_dump (). The difference is that the returned representation is legal PHP code.
You can set the second parameter of the function to TRUE to return the expression of the variable.
EG:
Var_export (array ('A', 'B', array ('A', 'bb ', 'cc') is no different from VAR_DUMP;
$var =var_export(array('a','b',array('aa','bb','cc')),TRUE)
After TRUE is added, it will not be printed again,
Instead, a variable can be directly output;
echo $var;
The output format correspondsvar_dump()
Print similar.