Php log recording method based on custom functions, php function log

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.