Let's talk about log printing specifications

Two recent on-site project problem location and troubleshooting are related to adding logs. This is also one of the more serious problems now. Many times, if there is a problem on site, if you look for R&D, you need to temporarily increase the log and then find the location of the replacement file on site. There are also some R&D logs that are easy to print. There are many logs when encountering problems, but there are not many keys to use. For this reason, I think it is necessary to standardize the log printing problem.

In particular, developers should also pay attention to whether their logs are printed in specifications. Doing a good job of printing logs is one of the basic qualities of coders. For this the developer should do the following,

  1. Ensure that the exception capture log is printed correctly, prohibit the behavior of capturing exceptions without doing any processing, and cannot directly print exceptions to the console.
  2. The run method in the thread does exception capture and log output to avoid the thread exception log being directly output to the console.
  3. Use the logging facade slf4j's interface API instead of using the concrete logging implementation framework API. Use placeholders to print logs instead of concatenating strings.
  4. Use the correct log level to print the log, only use error for serious program logic exceptions, output the info log at the key node of the program running, and print the debug log at the interface function call. Do not use the debug log in the production environment, let alone output large object files, such as image files, in the debug log.
  5. Additional log files can be added to API calls or APIs provided to third parties to facilitate troubleshooting of connection problems. The AOP mode can be uniformly used to print and output the function interface call log.
  6. For the useless debug logs that are frequently printed on the line, you can increase the log output level of the corresponding class. Avoid outputting too many useless logs to take up storage space.
  7. To learn and practice the log processing specification in the company, you can learn the exception log specification part of the Ali development protocol.

As the leader of the development team, you should pay attention to the promotion and implementation of log planning. When developing code reviews, you should also pay attention to whether the log printing is compliant, and whether to print logs in key places.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324857503&siteId=291194637