LOG4J configuration (Detailed version) ———— detailed log is the way to solve the bug

Source: Internet
Author: User

The only jar package you need is: Log4j-1.2.x.jar

I'm currently using Log4j-1.2.17.jar for so long everything is OK, log information is available



Configuration file Log4j.properties

# log4j Settings for log4j 1.2.x (via Jakarta-commons-logging) # # of five logging levels used by Log is (in order): # 1 . DEBUG (The Least serious) # 2. info# 3. warn# 4. error# 5. FATAL (the most serious) # [level], appenderName1, appendername2# Set root logger level, log output destination, log output destination # General Date output most Good set at WARN and higher, or tomcat boot slow and log content too miscellaneous Log4j.rootlogger=warn, Console, r# log output Path Log_home=/data/logs/com/wenniuwuren # Console---------------------------------------------------# Log Output Destination # Consoleappender (console) # Fileappender (file) # Dailyrollingfileappender (Generate a log file per day) # Rollingfileappender (a new file is generated when the file size reaches the specified size) # Writeappender (send log information in stream format to any specified place) # Jdbcappender (save log information to the database) log4j.appender.console= org.apache.log4j.consoleappender# Log Layout # htmllayout (layout as HTML table) # Simplelayout (level and information string containing log information) # Ttcclayout (contains information such as time, thread, category, etc.) # Patternlayout (can be flexibly assigned layout format, commonly used) log4j.appender.console.layout= org.apache.log4j.patternlayout# output Format #%c output log information The full name of the class that belongs to #%d the date or time of the output log point in time, the default format is ISO8601, or the format can be specified later, such as:%D{YYY-M-DD HH:MM:SS}, output similar to: 2002-10-18-22:10:28#%f the class name of the class to which the output log information belongs #%l the occurrence of the output log event where the statement that outputs the log information is in the number of lines of the class where it resides #%m the information specified in the output code, such as log ( Message), the message#%n outputs a carriage return newline character, the Windows platform is "RN", and the UNIX platform is "n" #%p output priority, i.e. debug,info,warn,error,fatal. If the debug () output is called, Debug, and so on #%r output the number of milliseconds that the application starts to output this log information #%t Output the thread name that generated the log event log4j.appender.console.layout.conversionpattern=%d [%t]%-5p [%c]-%m%nlog4j.appender.debug= org.apache.log4j.consoleappenderlog4j.appender.debug.layout= org.apache.log4j.patternlayoutlog4j.appender.debug.layout.conversionpattern=%d [%t]%-5p [%c]-%m%n# Console---------------------------------------------------log4j.logger.java.sql.resultset= Debuglog4j.logger.org.apache=warnlog4j.logger.java.sql.connection=debug log4j.logger.java.sql.statement= debuglog4j.logger.java.sql.preparedstatement=debuglog4j.logger.org.springframework= warnlog4j.logger.org.apache.activemq=warn# R------------------------------------------------------------------- ------------LOG4J.APPENDER.R=ORG.APACHE.LOG4J.ROLLINGFILEAPPENDERLOG4J.APpender. r.layout=org.apache.log4j.patternlayout# output Format LOG4J.APPENDER.R.LAYOUT.CONVERSIONPATTERN=[%D{YYYYMMDD HH:mm:ss}-%p ][%f:%l][%t]--%m%n# Log output path and log file name log4j.appender.r.file=${log_home}/wenniuwuren-system.log# Single log file maximum capacity log4j.appender.r.maxfilesize=1024kb# maximum number of backup files log4j.appender.r.maxbackupindex=10# R-------------------- -----------------------------------------------------------log4j.appender.stdout= org.apache.log4j.consoleappenderlog4j.appender.stdout.layout= org.apache.log4j.patternlayoutlog4j.appender.stdout.layout.conversionpattern=%d%p [%c]-<%m>% Nlog4j.logger.org.apache.ibatis=debuglog4j.logger.java.sql=debug


If it is a Web application, it also needs to be configured in XML (so that Tomcat loads the log4j when it is loaded):

<context-param><param-name>log4jconfiglocation</param-name><param-value>classpath: Log4j.properties</param-value></context-param><listener><listener-class> Org.springframework.web.util.log4jconfiglistener</listener-class></listener>


LOG4J configuration (Detailed version) ———— detailed log is the way to solve the bug

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.