Log Level [sl4j]-Simple Review

Source: Internet
Author: User



In the software, it is inevitable to use something like log4net, log4j, tracer to write logs. No matter what you use, these things are mostly similar and generally provide such five log levels:

Debug

Info

Warn

Error

Fatal

A level is higher than a level, but in specific development, there is no good article to explain how to select a level for adaptation. Record some of your opinions for future use.


=== Debug ===

The lowest level is generally not output during the actual operation of the system.


Therefore, this level of information can be used at will. Anyone who feels that it is helpful to know more about the system running status during debugging, such as the value of the variable, can output it for a look.


Of course, before each debug call, you must add If judgment.


=== Info ===

This should be used to feedback the current status of the system to the end user. Therefore, the output information here should be of practical significance to the end user, that is, the end user must be able to understand what it means.


From a certain point of view, the information output by info can be considered as part of a software product (just like the text on the interactive interface). Therefore, you need to be cautious about it.


=== Warn, error, fatal ===

Warnings, errors, and serious errors should all be detected in an abnormal state during system operation. The difference between them is that it is not that simple to distinguish between them. I roughly distinguish it like this:


The so-called warning should be that at this time some repairs should be carried out, and the system should be able to be restored to a normal state, and the system should be able to continue running.


The so-called error means that some corrective work can be carried out, but it cannot be determined that the system will work normally. In a future stage, the system may be due to the current problem, it may cause an irreparable error (such as downtime), but it may still work until it is stopped, and no serious problem occurs.


The so-called fatal is very serious. It is certain that this error cannot be fixed, and if the system continues to run, it will inevitably become messy. At this time, the best measure is not to try to restore the system status to normal, but to keep the system valid data as much as possible and stop running.


That is to say, the specific one in warn, error, and fatal is determined based on the potential impact of the current problem on the future. If there is no impact on the future, warning: If it must be a serious problem in the future, then fatal will not be able to determine what will happen, then error will occur.


=== Some questions ===

However, in actual use, there are still some specific problems based on the above considerations. The most common thing is to open the output log to that level in the final product?


For example, if an output window exists in an application, some system status information will be output to this output window. Because the info level is so low, to enable users to see valid output information, the log level must be open to the info level. However, the level of warn is higher than that of info, so users have to see some warn information. In fact, we have assumed that the warn information does not affect the normal operation of the system. This generally only indicates that there are some minor bugs in the system that have not been found or modified. The warn information may confuse and even panic the end user. What should I do if the system sends a warning?


In my opinion, the info level should be higher than warn. The warn information is the same as the debug level and should be used in product testing and debugging, info, erro, and fatal must be used after the product is released.


Currently, the solution I use is to add a corresponding system assertion to warn, error, and fatal to ensure that when such a problem occurs, it is in the debugging phase, you can get a prompt immediately. After the software is released, the information can also be recorded in log files.


Log Level [sl4j]-Simple Review

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.