Set the time zone in PHP to record the log file implementation code

Source: Internet
Author: User
The implementation code for setting the time zone to record log files in php. For more information, see

The implementation code for setting the time zone to record log files in php. For more information, see

The Code is as follows:


Date_default_timezone_set ('Asia/Hong_Kong '); // set time zone
Set_error_handler ("myHandler"); // set error handler
$ Chinatime = date ('Y-m-d H: I: s'); // get current time
$ Max_size = 500000;
Try
{
$ Content = "Hello WeiXin! ";
Logger2 ($ content );
// Throw new Exception ("Value must be 1 or below AAAAAAAAAAAAAAAAA ");
}
Catch (Exception $ e)
{
Logger2 ("Exception Message:". $ e-> getMessage ());
}
// Record operation log into. log file
Function logger ($ log_content)
{
Print_r (date ('H: I: s'). "". $ log_content ."
");
$ Log_filename = date ("Ymd"). ". log ";
$ File = fopen ($ log_filename, "a + ");
Fwrite ($ file, date ('H: I: s'). "". $ log_content. "\ r \ n ");
Fclose ($ file );
}
// Record operation log into. log file
Function logger2 ($ log_content)
{
Global $ max_size;
Print_r (date ('H: I: s'). "". $ log_content .""."
");
$ Log_filename = date ("Ymd"). ". log ";
If (file_exists ($ log_filename) and (abs (filesize ($ log_filename)> $ max_size) {unlink ($ log_filename); sleep (1 );}
File_put_contents ($ log_filename, date ('H: I: s'). "". $ log_content. "". "\ r \ n", FILE_APPEND );
}
// Error handler function
Function myHandler ($ level, $ message, $ file, $ line, $ context)
{
Logger (" [ERROR]LEVEL: $ level, MESSAGE: $ message, FILE: $ file, LINE: $ line, CONTENT: $ context ");
Die ();
}
?>



Http://txw1958.cnblogs.com/

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.