Select the log level correctly, and select the log level correctly.
The importance of logs is self-evident when developing an application. However, a large number of junk logs are sometimes found in logs. Junk logs are logs that do not need to be known, or these logs have no effect on application viewing and tracking. For these considerations, the common log frameworks have set the log level. However, when writing a program, which log level should you choose? There is no unified standard and no one will teach you how to do it. The following describes how to use these log levels during development.
Generally, there are several log levels:
- FATAL (CRITICAL)
- ERROR
- WARN
- INFO
- DEBUG
Their weight ranges from large to small. After we set the log level, other logs with lower weights will be ignored.
Different Languages and libraries have different log implementations, which are easy to use. However, the key to using logs is not the database itself, but the appropriate log level.
Select the corresponding log level in different scenarios.
FATAL(CRITICAL)
Indicates that the entire service is stopped (or the entire service needs to be stopped) because of the most serious error ). Simply put, the service is dead.
ERROR
Indicates that an error must be handled immediately. After such errors occur, you can allow the program to continue running, but it must be corrected immediately. If it is not corrected, the corresponding service cannot be completed.
WARN
It indicates that a potential error exists or an operation that is easy to cause an error is triggered. The program can continue to run, but you must pay more attention to it.
INFO
This output level is commonly used for business event information. For example, the processing of a business is completed, or some information in the business processing process.
This output level is also commonly used to output messages to be seen that have a great impact on the system, such as database updates and additional requests sent by the system.
DEBUG (or TRACE, FINE)
This output level is used for debugging in the development phase. It can be the output of variable values at key logical points, or the verification of function return values.
In addition, if you write some util tool classes, you can also use debug to add logs.
If you are writing Helper (Service-assisted class), this should be related to business processing, so you should use info.