About log4j more comprehensive configuration

Source: Internet
Author: User
The simple configuration of log4j makes it more and more applications: The log4j configuration file realizes output to console, file, rollback file, send log mail, output to database log table, custom label and so on. Choose its one or two use is enough, Log4j.rootlogger=debug,console,a1,im log4j.addivity.org.apache=true #  applied to the console Log4j.appender.console=org.apache.log4j.consoleappender Log4j.appender.threshold=debug Log4j.appender.console.target=system.out Log4j.appender.console.layout=org.apache.log4j.patternlayout log4j.appender.console.layout.conversionpattern=[framework] %d - %c -%-4r [%t] % -5p %c %x - %m%n #log4j. appender.console.layout.conversionpattern=[start]%d{date}[date]%n%p [Priority]%n%x[ndc]%n%t[thread] n%c[category]%n%m[message]%n%n #应用于文件 log4j.appender.file= Org.apache.log4j.FileAppender Log4j.appender.file.file=file.log Log4j.appender.file.append=false Log4j.appender.file.layout=org.apache.log4j.patternlayout log4j.appender.file.layout.conversionpattern=[ framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n # Use  tHis layout for logfactor 5 analysis #  applied to file rollback log4j.appender.rolling_file= Org.apache.log4j.RollingFileAppender Log4j.appender.ROLLING_FILE. Threshold=error Log4j.appender.ROLLING_FILE. File=rolling.log Log4j.appender.ROLLING_FILE. Append=true Log4j.appender.ROLLING_FILE. MAXFILESIZE=10KB Log4j.appender.ROLLING_FILE. Maxbackupindex=1 Log4j.appender.rolling_file.layout=org.apache.log4j.patternlayout log4j.appender.ROLLING_ file.layout.conversionpattern=[framework] %d - %c -%-4r [%t] %-5p %c % x - %m%n #应用于socket Log4j.appender.socket=org.apache.log4j.rollingfileappender Log4j.appender.socket.remotehost=localhost log4j.appender.socket.port=5001 log4j.appender.socket.locationinfo= True # set up for log facter 5 log4j.appender.socket.layout= Org.apache.log4j.PatternLayout log4j.appender.socet.layout.conversionpattern=[start]%d{date}[date]%n%p[priority ]%n%x[ndc]%n%t[thread]%n%c[category]%n%m[message]%n%n # log factor 5 appender log4j.appender.lf5_appender= Org.apache.log4j.lf5.LF5Appender Log4j.appender.LF5_APPENDER. maxnumberofrecords=2000 #  send log to mail Log4j.appender.mail=org.apache.log4j.net.smtpappender Log4j.appender.mail.threshold=fatal log4j.appender.mail.buffersize=10 log4j.appender.mail.from=web@www.wuset.com Log4j.appender.mail.smtphost=www.wusetu.com Log4j.appender.mail.subject=log4j message Log4j.appender.mail.to=web@www.wusetu.com Log4j.appender.mail.layout=org.apache.log4j.patternlayout log4j.appender.mail.layout.conversionpattern=[framework] %d - %c -%-4r [%t] %-5p  %c %x - %m%n #  for Database Log4j.appender.database=org.apache.log4j.jdbc.jdbcappender Log4j.appender.database.url=jdbc:mysql://localhost:3306/test log4j.appender.database.driver= Com.mysql.jdbc.Driver Log4j.appender.database.user=root log4j.appender.database.password= Log4j.appender.database.sql=insert into log4j  (message)  VALUES  (' [framework] %d - %c -%-4r [%t] %-5p %c  %x - %m%n ') log4j.appender.database.layout=org.apache.log4j.patternlayout log4j.appender.database.layout.conversionpattern=[framework] %d - %c -%-4r [%t]  %-5p %c %x - %m%n Log4j.appender.a1=org.apache.log4j.dailyrollingfileappender Log4j.appender.a1.file=samplemessages.log4j log4j.appender.a1.datepattern=yyyymmdd-hh '. log4j ' Log4j.appender.a1.layout=org.apache.log4j.xml.xmllayout #自定义Appender log4j.appender.im =  Net.cybercorlin.util.logger.appender.IMAppender log4j.appender.im.host = mail.cybercorlin.net Log4j.appender.im.username = username Log4j.appender.im.password = password Log4j.appender.im.recipient = corlin@cybercorlin.net log4j.appender.im.layout= Org.apache.log4j.PatternLayout log4j.appender.im.layout.conversionpattern =[framework] %d -  %c -%-4r [%t] %-5p %c %x - %m%n

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.