PHP / Simple log function

function logToFile($filename, $msg)
{
   // open file
   $fd = fopen($filename, "a");
   // append date/time to message
   $str = "[" . date("Y/m/d h:i:s", mktime()) . "] " . $msg;
   // write string
   fwrite($fd, $str . "\n");
   // close file
   fclose($fd);
}
Here's an example of the output:
[2002/11/25 06:02:42] Non-numeric variable was found
[2002/11/25 06:02:42] No fish found
[2002/11/25 06:02:43] Where is a beer?
(c) http://www.go4expert.com/articles/simple-logging-php-t1036/

No comments:

Post a Comment