Correct selection of log levels

Source: Internet
Author: User

To develop an application, the importance of logging is self-evident. However, it is sometimes found that a large number of garbage logs appear in the log. The so-called spam logs are logs that you do not need to know, or the logs are not useful for viewing or tracking apps. It is also (but not only) that the common log framework sets the log level for these issues. But when writing a program, which of these log levels to choose, does not have a uniform standard, and no one teaches you how to do it. Here's how I use these log levels in development.

In general, there are several log levels:

    • FATAL (CRITICAL)
    • ERROR
    • WARN
    • INFO
    • DEBUG

They have weights from big to small. When we set the log level, other logs that are lower than its weight are ignored.

Different languages, different libraries have different log implementations, the use of the method is relatively simple. But the key to using log is not the library itself, but the right log level in the right place.

In different scenarios, the corresponding log level should be selected.

FATAL (CRITICAL)

Represents the most serious error that can cause the entire service to stop (or need to stop the entire service). In short, the service is dead.

ERROR

Represents an error that must be dealt with immediately. This type of error can later allow the program to continue to run, but must be fixed immediately, if not corrected, will result in the inability to complete the corresponding business.

WARN

Represents a potential error or triggers an error-prone operation. The program can continue to run, but must be more careful.

INFO

This output level is a common term for business event information. For example, the completion of a business, or some information in the process of business processing.

This output level is also often used to output some messages that need to be seen that have a large impact on the system, such as database updates, additional requests sent by the system, and so on.

DEBUG (or Trace, FINE)

This output level is used for debugging in the development phase, which can be the output of variable values for a few logical keys, or the validation of function return values, and so on.

In addition, if you write some of the Util tool classes, you can also use debug if you need to add a log.

If you're writing a helper (Business helper Class), this should be a business-related process, so you should use info.

Correct selection of log levels

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.