1. The role of logs
Logs are the number of key nodes during the system operation. These logs are easy to record when there are problems in the system and are easy to find problems. Print parameters must be meaningful and coherent. To facilitate quick positioning of problems.
2. Log printing specifications
Regular log specification writing method:
("Verification code: {} ", code);
("Request parameter: {}, verification code: {} ", param,code);
( ("Request parameter name: %s, Request parameter age: %d", name, age));
These are concise and highly readable. The irregular writing method is as follows
(”####### code verification code: + code):
("Verification code login jsonResult :"+ (jsonResult));
Exception log specification writing method:
logger. error("Login sends verification code exception, mobile phone number: {}, exception details: {}", phone, e);
Irregular writing of exception logs
(());
Explanation (), can only tell you what exception appears, but it does not tell you which line the exception reported. 2. No business scenario or business keywords are recorded.
In addition, some people try to catch directly () and write this way first, it will not record the log file. And it will take up memory. Consumes system performance.
The debug log recommends that the production environment be shut down.
The attention sensitive fields printed in the log should be desensitized
3. Log files
Taking logback as an example, a log file is generally created with dates, for example, the configuration is as follows
<!-- Circular Policy:Create log files based on time --> <rollingPolicy class=""> <!-- Log file name format --> <fileNamePattern>${}/info/%d{yyyy-MM-dd}-</fileNamePattern> <!-- Maximum storage time:30sky--> <maxHistory>30</maxHistory> </rollingPolicy>
This is the end of this article about Spring Log Specifications and Functions. For more relevant Spring Log Specifications, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!