当前位置:网站首页>Error log format and precautions

Error log format and precautions

2022-06-25 02:37:00 InfoQ

Print in the program code ERROR Basic principles of error logging :

  • Describe as completely as possible :  Every error log needs a complete description : What's wrong in what scenario ,  What causes it ( Or what are the possible reasons , Like parameters 、 Other system data, etc ),  How can it be solved ( Or other relevant tips for solution );
  • Be as specific as possible :  For example, insufficient resources , It can be described in detail to : What specifically refers to the lack of resources , Whether it can be directly indicated in the program , For example, the resources of the route pool are insufficient or Interface access current limiting .
  • Describe as directly as possible :  The most intuitive error log should allow people to read the error log information , You can find out what caused the problem , How to solve , Instead of slowly debugging the program , Or guess the real reason .

In a nutshell , The error log should do : Even without code context , It can also clearly describe what happened .

The level of logging :

  • info  It is used to print the normal status information that the program should appear ,  Easy to track and locate , Usually used to locate logic bug.
  • warn  It shows that the system is slightly unreasonable, but it does not affect the operation and use , The key to the level of this log is that it does not affect the operation , You can ignore .
  • error  Indicates that there are system errors and exceptions , The target operation cannot be completed normally .error Manual intervention required .

ERROR Log format

[ Class name { Required }] [ Method name { Required }] [ Error phenomenon { Required }] [ Conditions { Required }] [ Possible causes { optional }] [ What do I need to do { optional }][ The stack information ]

  • Class name : Class name .
  • Method name : Method name .
  • Error phenomenon : Describe the error phenomenon , such as " Interface timeout " perhaps " The interface returned an exception ".
  • Conditions : Interface parameters or classes DTO Input parameter serialization result .
  • Possible causes : Describe the possible causes of the error , such as " The cache is full " perhaps " XXX permission cannot be obtained ", Error code , Non essential election .
  • What do I need to do : Describe recommended actions ,  such as " Update a key value cache "," Modify so and so permission ", Non essential election .

General error  ,  To indicate the scene in which it happened , May facilitate the follow-up statistical work .
原网站

版权声明
本文为[InfoQ]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206242259158463.html