Copy Code code as follows:
<body>
<?php
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 aaaaaaaaaaaaaaaaaaa");
}
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." <br/> ");
$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." "." <br/> ");
$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 ("<b>[ERROR]</b> level: $level, message: $message, FILE: $file, line: $line, CONTENT: $context");
Die ();
}
?>
</body>
Original website: http://txw1958.cnblogs.com/