Thursday, 11 July 2024

Formatting the Date & Time Format in PHP Error Log

The default log output looks like:
[11-Jul-2024 04:19:33 UTC] The logged Info after the date
The following code will change it to your local time which makes sence if all your messages come from a single timezone:
$TZ = date_default_timezone_get();  //returns 'UTC'
            date_default_timezone_set('Australia/Melbourne');
$TZ = date_default_timezone_get();  //returns 'Australia/Melbourne'
The log will now show the correct local date time (I'd prefer am/pm but whatever):
[11-Jul-2024 14:19:33 Australia/Melbourne] The logged Info after the date
The above doesn't change the format, just the timezone it displays in, however you can override the default logging to define the date as you wish as as shown here

No comments: