Log4j configuration, log4j

Source: Internet
Author: User

Log4j configuration, log4j
First configure the source file log4j. properties

The following is an important explanation:

Log4j. rootLogger = DEBUG, CONSOLE, FILE ----- configure the root Logger. The first word "DEBUG" after the equal sign indicates the output level (there are five levels of fatal errorwarn info debug. the more detailed the output is, in order, each level contains all the preceding outputs and shields all the subsequent outputs. Here, we recommend two types: ERROR: only ERROR information is recorded; DEBUG: detailed information of all errors is recorded. In the production configuration, disable the "apply to CONSOLE" option and only enable FILE). The following two consoles and files represent the location of log output, and the following two can be named at will, to be clear and easy to understand, you can use words with a glance. For example, the console represents the console output, and the file represents the file output.

Log4j. appender. CONSOLE = org. apache. log4j. consoleAppender ------- pay attention to the CONSOLE before the equal sign, which corresponds to your definition above. This sentence means that the CONSOLE is defined as org. apache. log4j. consoleAppender (log4j console output). Log4j provides the following appender types:

Org. apache. log4j. leleappender (console)

Org. apache. log4j. FileAppender (file)

Org. apache. log4j. DailyRollingFileAppender (a log file is generated every day)

Org. apache. log4j. RollingFileAppender (a new file is generated when the file size reaches the specified size)

Org. apache. log4j. WriterAppender (send log information to any specified place in stream format)

Log4j. appender. CONSOLE. layout = org. apache. log4j. PatternLayout ------- defines the output layout (output format) used by log4j ).

Log4j provides the following four layout styles:

Org. apache. log4j. HTMLLayout (layout in HTML form)

Org. apache. log4j. PatternLayout (you can flexibly specify the layout mode, that is, you can customize the output style ),

Org. apache. log4j. SimpleLayout (including the log information level and information string ),

Org. apache. log4j. TTCCLayout (including the log generation time, thread, category, and so on)

Log4j. appender. CONSOLE. layout. conversionPattern = % d {MM-ddHH: mm: ss} [% c-% L] [% t] [%-4r]-% m % n ------- this is the output format customized for PatternLayou, this article focuses on the printing parameters. Log4J uses a format similar to the printing format of the printf function in C language to format log information.

% M output the specified message in the code

% P output priority, namely DEBUG, INFO, WARN, ERROR, FATAL

% R the number of milliseconds it takes to output the log information from application startup to output

% C output category, usually the full name of the class

% T name of the thread that outputs the log event

% N output a carriage return line break. For Windows, the value is \ r \ n, and for Unix, the value is \ n. That is, one line is occupied by a hop message.

% D date or time of the log output time point, followed by a pair of curly brackets for custom format

% C output category, usually the full name of the class

% L accurate to line

% X output alignment

The following sentence refers to the one that I extract from the log information output from my console. The comparison of the definition formats above is similar.

09-3010: 34: 04 [com. opensymphony. xwork2.config. providers. InterceptorBuilder-45] [main] [106]-No interceptor found for name = includeMethods

Log4j. appender. FILE. File = D:/logs/log4j. log -------- define the location and FILE name of the output File

Log4j. appender. FILE. MaxFileSize = 1 MB ---------- defines the size of each FILE. If the size is exceeded, a new FILE is created. Note that the unit is MB or KB.

Run the command to check whether the exception information is saved in error. log.

 

 

Related Article

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.