Link to home
Start Free TrialLog in
Avatar of Mark Brady
Mark BradyFlag for United States of America

asked on

php error_log date and time format settings

I know I should know this but it's driving me nuts. How do you set the date and time format in php error_log(). I have set the default_time_zone setting and made sure the system date and time zones are correct. Here is what the error log puts out

[30-Jun-2012 01:17:09 UTC] test
[30-Jun-2012 01:17:10 UTC] test
[30-Jun-2012 01:32:27 UTC] test
[30-Jun-2012 01:32:32 UTC] test..... etc

I want it to put out

[2012-06-30 22:17:09] test
[2012-06-30 22:17:09] test
[2012-06-30 22:17:09] test
[2012-06-30 22:17:09] test.... etc

I would prefer it doesn't use UTC as I have set my timezone to 'America/New_York'

We are in Florida so it should be reporting as EST but the most important part is to have the error_log file record the system time and in the correct format ie: 'Y-m-d H:i:s'

Thanks for the help. I should know this stuff but for years I have been using an error log at work that records the date properly. I'm just not at work now :)
Avatar of rinfo
rinfo

You can either set default time zone in ini
date.timezone = 'America/New_York'
or you can add a line in the script where you are using date
date_default_timezone_set('America/New_York');

and finally put the date format explicitly in the error_log
error_log('['.date('YYYY-MM-dd HH:mm:ss').']'.$msg.........)
sorry that would be
date('Y-m-d H:i:s')
Avatar of Mark Brady

ASKER

Nope that's no good. Like I said, on my work system I don't need to format the date to use error log.

err_log('test'); will print [2012-06-30 22:17:09] test

Why should I have to add the date format at home?

Besides, your way would produce this result

[30-Jun-2012 01:17:09 UTC][2012-06-30 01:17:09] test

Yuk but thanks anyway

There is a way to explicitly set the format that is used by error_log. It may be a computer system setting for all I know but I use Ubuntu and I can't see how to get the date formatted like that anywhere.
ASKER CERTIFIED SOLUTION
Avatar of Mark Brady
Mark Brady
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I did not get a satisfatory result from this question. I wrote my own error log handler and have it customized to suit my needs. I did spend a lot of time looking through Google to find a solution but it seems php don't even control the error log apart from the filename and sending entries into it.

It would be a far wiser solution for PHP to get rid of the external companies software and write their own error handler to deal with error_log() entries. That way we could format the date at least to suit our particular situations.