Simple php custom error log

Source: Internet
Author: User
I often read php error logs and rarely have the opportunity to write logs by myself. After Reading Wang Jian's "Best log practices", I think it is necessary to write clear and well-structured logs. Before writing logs, let's ask ourselves: Why do we sometimes need to record custom logs? Instead of using the system's default logging method? I think there are two

I often read php error logs and rarely have the opportunity to write logs by myself. After Reading Wang Jian's "Best log practices", I think it is necessary to write clear and well-structured logs. Before writing logs, let's ask ourselves: Why do we sometimes need to record custom logs? Instead of using the system's default logging method? I think there are two

I often read php error logs and rarely have the opportunity to write logs by myself. After Reading Wang Jian's "Best log practices", I think it is necessary to write clear and well-structured logs.

Before writing logs, let's ask ourselves: Why do we sometimes need to record custom logs? Instead of using the system's default logging method?

I think there are two reasons:

1. The team needs a uniform log format for easy management

2. A large number of useless error logs occupy hard disk space and only meaningful logs need to be recorded.

So, practice it.


1. Open your php. ini2. open the log and set

log_errors = Off

Change

log_errors = On

3. Save php. ini and restart the web server. 4. Add the following code at the beginning of your code:

1
 

5. Try to write an error code after the code.

echo 1/0;

Check whether a log file exists in the defined path? :)

Note:The following errors cannot be handled by user-defined functions: E_ERROR, E_PARSE, E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING, and most of the E_STRICT generated in the file where the set_error_handler () function is called.

However, when you enable the Error Log System (php. log_error = on in ini and specify the System Log File (also php. error_log = path name) in ini, and after error_reporting is enabled, all the above errors will be recorded in your defined file as system error logs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.