PHP error handling error log
In some companies, there is a special log collection system. The log collection system will silently help you collect errors, warnings, and prompts behind the scenes.
There are also some companies that do not have a dedicated log collection system and collect the running logs from the server through files.
Among them: PHP errors and warnings must be received.
Then the question comes - if users are not allowed to see it, and the error reporting level is set, how to collect errors into the log system?
Here are the relevant configuration items that need to be used in php.ini. These two configuration items are:
Parameter | Configuration item | Description |
---|---|---|
log_errors | on/off | Whether to enable logging |
log_errors_max_len | Integer type, default 1024 | Maximum record length of single-line errors |
error_log | syslog or specified path | Where the error log is recorded |
Note:
1. The log_errors and log_errors_max_len in the table are very easy to understand.
2. The error_log specifies the path on which the error will be stored. The syslog in the configuration items may be a bit difficult to understand. syslog refers to system recording. Windows system is in the log collector of the computer. Linux defaults to: /etc/syslog.conf
[Extension]Learn about the knowledge points. If the Linux system is started or log collection is modified. May be stored on third-party dedicated log collection servers.
In addition, PHP also specially prepared a custom error log function for us:
bool error_log (string $error message[, int $error message type = 0 [, string $storage Target]] )
This function can send error information to the error log of the web server, or to a file.
Commonly used error message types:
Error message types | Description |
---|---|
0 | Send to the default error_log specified location |
1 | Send to the specified email location |
3 | Send to the specified file location |
Example:
Note:## Sending emails in #error_log may be unfamiliar to beginners, so you don’t need to master some knowledge.