error_log
Writes a message to the error log.
Syntax
error_log(string $message, int $message_type = 0, ?string $destination = null): boolParameters
| Parameter | Type | Description |
|---|---|---|
| $message | string | The message text. |
| $message_type | int | Optional. `3` writes to the file given as the third argument. |
| $destination | ?string | Optional. The path to a log file. |
Return value
bool`true` if the message was written.
Examples
Writing to a log file of your own:
<?php
$log = sys_get_temp_dir() . '/ref-app.log';
file_put_contents($log, '');
error_log("Payment failed: order 15\n", 3, $log);
echo file_get_contents($log);Output:
Payment failed: order 15Notes
Without the second and third arguments the message goes to the server log — the user does not see it. Do not log passwords or card numbers.
See also
- var_dump — Prints the type and the value — for debugging.
- set_error_handler — Sets a custom function to handle PHP warnings and notices.
Related recipes
In the tutorial
- Errors and debugging — The kinds of PHP errors, error display settings, the log, turning warnings into exceptions and debugging techniques.