Java Project Logging Scenario

Source: Internet
Author: User

I. Overview


1, the use of SLF4J as a log API, using Logback as a log output tool, with SLF4J Bridge to replace the log4j and commons-logging.

2, using trace (Tracking), debug (Debug), info (information), warn (warning), error (Error), Fatal (fatal) a total of 6 log levels.

3, the use of dev (development environment), test (testing environment), production (production environment) and other different log configuration, according to the environment variable automatic identification.

4, special records, need to write a large amount of log files, should use asynchronous thread to write files.


Second, log level definition

Trace (Trace), Debug (Debug), info (information), warn (warning), error (Error), Fatal (fatal) a total of 6 log levels.


Log-level usage principles:

1, Fatal (fatal error) Principle of use

Fatal is a system-level exception, and a fatal error occurs, representing the entire or core functionality of the server that is no longer working.

1 should be checked when the server is started, if there is a fatal error, throw the exception directly, so that the server does not start up (started also does not work properly, as not to start).

2 If a fatal error occurs after the server is started, record the error log at the fatal level, preferably at the same time triggering related repair and alarm work (for example, sending alert messages to development and maintenance personnel).


2, error (wrong) use of the principle

Error is a critical exception at the functional or logical level, an error-level exception occurs, and a function or critical logic encounters a problem that does not work properly.


3, warn (warning) principle of use

Warn is used in some logic unconventional, there are some minor faults but there is no big impact, or important data is modified, or some operations need attention.


4, info (information) Use principle

Info is used to record useful, critical information, which is usually infrequent and is recorded only where it is initialized or where it is important to operate.


5, debug (debugging) Principle of Use

Debug is used to record debugging information, to facilitate viewing of program execution and related data, and to understand the dynamics of the program.


6, trace (tracking) The use of the principle

Trace is used to record more detailed debugging information that does not need to be printed every time it is debugged, only when more detailed debugging information is required.


7, the project stable operation log Amount

1 under normal circumstances, the trace log is at least 100 times times the debug log,

Trace level of Log Volume: Debug level Log amount > 100:1,

That is, the trace log is very numerous and the debug log is relatively small.


2 Debug-level log Volume : Info-level log volume > 1000:1,

That is to say, normally, the info log is very small and only in some important locations will output the info log.


3 error log and warn log, under normal circumstances, almost 0, when an exception occurs, the error log and warn log volume is also controllable, not exceeding the debug level maximum log volume.


Third, log output (Appender) category


Divided into 5 general categories:

File_exception (Exception log, including error and warn)

File_app (Application log, including the log below the current application package and other logs above the debug level)

File_info (General Information log)

File_debug (debug log)

FILE_TRACE (tracking log)

Sysout (console output, which can include all of the above logs)

Extended class: Includes the asynchronous output of the log, or special business log.


An example is provided:

If

The Main Package currently applied is cn.zollty.lightning

Root_level is trace, Application log level is debug

The following logs are printed:

1 2 3 4 5 6 7 8 9 10 11 12-13

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.