If you use an error log file, you can simply add your preferred date format for the log message.
If you use the standard Apache log file , you cannot change the log format via php.
Instead, you should change the entire format of the Apache error log in httpd.conf via the LogFormat keyword: replace the existing format with the desired format.
Here you can find the complete syntax guide for LogFormat .
Edit:
After your last comment, I looked over the Internet and I performed some tests, then I understand that my previous answer is incorrect: there is no way to change the behavior of error_log() in php. In my case (I have Apache installed), the error_log() ) function outputs the Apache log format even to the user log file (defined via ini_set('error_log') ).
In your case, I think php uses the OS log format (are you sure you don't have Apache installed, even if you don't use it?).
Alternative: trigger_error ()
You can set your fully custom error log format using trigger_error() - along with set_error_handler() - instead of error_log() :
function myErrorHandler( $errType, $errStr, $errFile, $errLine, $errContext ) { $displayErrors = ini_get( 'display_errors' ); $logErrors = ini_get( 'log_errors' ); $errorLog = ini_get( 'error_log' ); if( $displayErrors ) echo $errStr.PHP_EOL; if( $logErrors ) { $message = sprintf( '[%s] %s (%s, %s)', date('dm H:i'), $errStr, $errFile, $errLine ); file_put_contents( $errorLog, $message.PHP_EOL, FILE_APPEND ); } } ini_set( 'log_errors', 1 ); ini_set( 'error_log', 'file.log' ); set_error_handler( 'myErrorHandler' ); trigger_error( 'Test' );
In the above example, trigger_error will add a line like this to the .log file:
[15-02 09:43] Test (Script/File/Path.php, 12)
The error_handler all system errors is handled by the user-defined function. To simulate a system error, you should use trigger_error() instead of error_log() .
To maximize tuning, you can go to trigger_error optional error_type parameter:
trigger_error( 'Test', E_WARNING );
will result in a warning level error; The default value of error_type is E_USER_NOTICE . The type of error is the first parameter ( $errType ) in the user-defined function, therefore, inside the user-defined function of the error handler, you can change the behavior depending on the type of error.
In my previous simple example, a user-defined function also processes some ini directives, so you can use ini_set in combination with set_error_handler . Note that you can change the variable names of custom function parameters, but not the order , because this is determined by the php internal error system.
If you decide to use set_error_handler() , read the documentation carefully to understand the behavior and exceptions.