You can use your own function for this, error_log , it basically writes the data in the file defined in php.ini:
error_log('Erro customizado'); // mesmo que: error_log('Erro customizado', 0);
But if you want to write to a certain file you can use it like this (changing the second parameter to 3
, by default it is 0):
error_log('Erro customizado' . PHP_EOL, 3, '/home/usuario/meulogdeerror.log');
In windows it should look something like:
error_log('Erro customizado' . PHP_EOL, 3, 'C:/wamp/log/meulogdeerror.log');
You may also want to send by email, so use parameter 1:
error_log('Erro customizado', 1, '[email protected]');
Note that in this case it is necessary to configure the fourth parameter called $extra_headers
, this last parameter is only used in the case of emails
bool error_log ( string $message [, int $message_type = 0 [, string $destination [, string $extra_headers ]]] )
You have 4 log types as you set the second parameter $message_type
:
-
0
message is sent to the PHP logging system, using the operating system logging system or to a file, depending on what is set in the error_log
directive in php.ini. This is the default option.
-
1
message is sent to the email address in $destination
. This is the only type of message where the fourth parameter $extra_headers
is used.
-
2
No longer an option, I believe it was used only supported in PHP3
-
3
message is added to the file set to $destination
. A new line is not automatically added to the end of the string, which can make the messages stay on the same line, so you can use PHP_EOL
as I showed in the examples above.
-
4
the message will be sent directly to the SAPI log, I believe that if you use apache it will go to the Apache log.