...

View Full Version : How to add a Timestamp to fwrite logging to disk? [PHP5]



Shaitan00
03-26-2009, 05:59 AM
I am currently using fwrite(...) to log traces to a log file, seems to be working like a charm - but now I would like to beef it up a little.
Instead of simply having the error messages, I wanted to add a TimeStamp to the head of the string, making it easier to find out when the issue occured.

Currently I have the following


if (fwrite($this->hFile, $string."\r\n")) return true;


How can I add a timestamp to this in PHP5?
Thanks,

oesxyl
03-26-2009, 06:08 AM
I am currently using fwrite(...) to log traces to a log file, seems to be working like a charm - but now I would like to beef it up a little.
Instead of simply having the error messages, I wanted to add a TimeStamp to the head of the string, making it easier to find out when the issue occured.

Currently I have the following


if (fwrite($this->hFile, $string."\r\n")) return true;


How can I add a timestamp to this in PHP5?
Thanks,
you can use time():

http://www.php.net/manual/en/function.time.php

best regards

_Aerospace_Eng_
03-26-2009, 06:09 AM
Create a variable that contains the current date and time, then just concatenate it to $string. You can use php's date() function for this.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum