Select the log level correctly, and select the log level correctly.

Source: Internet
Author: User

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.

 

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.