How to quickly locate the production Environment bug by php

want to know how you locate the bug in the production environment. I see many friends say to add a log, but which location is more appropriate for me?
I remember that in an interview, an interviewer kept asking where it would be appropriate to add a diary, but there was no answer at that time!

Php
May.18,2022

set_error_handler
set_exception_handler


if you use framework development, many frameworks have their own packaged logging functions.
of course, you can also write your own logging method, which you can use to log when you develop.
logs are generally recorded by developers. For example, an error occurred in the execution of a sql statement, and logging is made according to the operation of the sql.
of course, you can't say that you write a piece of code to log after every sql is executed, so logs are usually recorded in some important places, such as functions involving money.
the bug of a general production environment is provided artificially. For example, after the operation, you find that a certain function is wrong, and then there is feedback. According to the feedback bug, add a log to its code block, run and debug in the production environment.


the basic principle is modularization, distinguishing boundaries, and then typing log in and out position.

for example:

request a third party, what request was sent and what response was received?

connected to the database, what sql statement was sent and what content was received

call a function, what to input, what to output.

of course, the important point is that you can't type so many logs all the time in a production environment, so logs should be turned on and off on demand, but when there is a problem to troubleshoot, open the corresponding log and close it after confirmation

.
Menu