log4j output logs to different files by level

Source: Internet
Author: User

Log4j.rootlogger=info,stdout,info,debug,error
Log4j.appender.stdout=org.apache.log4j.consoleappender
Log4j.appender.stdout.layout=org.apache.log4j.patternlayout
log4j.appender.stdout.layout.conversionpattern=[%-5p] [%d{hh:mm:ss}]%c-%m%n
 
Log4j.logger.info=info
Log4j.appender.info=org.apache.log4j.dailyrollingfileappender
Log4j.appender.info.layout=org.apache.log4j.patternlayout
log4j.appender.info.layout.conversionpattern=[%-5p] [%d{hh:mm:ss}]%c-%m%n
log4j.appender.info.datepattern= '. ' YYYY-MM-DD
Log4j.appender.info.Threshold = info
log4j.appender.info.append=true
Log4j.appender.info.file=${webapp.root}/web-inf/logs/info.log
 
Log4j.logger.debug=debug
Log4j.appender.debug=org.apache.log4j.dailyrollingfileappender
Log4j.appender.debug.layout=org.apache.log4j.patternlayout
log4j.appender.debug.layout.conversionpattern=[%-5p] [%d{hh:mm:ss}]%c-%m%n
log4j.appender.debug.datepattern= '. ' YYYY-MM-DD
log4j.appender.debug.Threshold = Debug
log4j.appender.debug.append=true
Log4j.appender.debug.file=${webapp.root}/web-inf/logs/debug.log

Log4j.logger.error=error
Log4j.appender.error=org.apache.log4j.dailyrollingfileappender
Log4j.appender.error.layout=org.apache.log4j.patternlayout
log4j.appender.error.layout.conversionpattern=[%-5p] [%d{hh:mm:ss}]%c-%m%n
log4j.appender.error.datepattern= '. ' YYYY-MM-DD
log4j.appender.error.Threshold = Error
log4j.appender.error.append=true

Log4j.appender.error.file=${webapp.root}/web-inf/logs/error.log


also describe a more comprehensive log4j.properties resource file

Log4j.rootlogger=debug,console,dailyfile,im
log4j.additivity.org.apache=true
# Consoles (console)
Log4j.appender.console=org.apache.log4j.conSoleappender
Log4j.appender.console.threshold=debug
log4j.appender.console.immediateflush=true
Log4j.appender.console.target=system.err
Log4j.appender.console.layout=org.apache.log4j.patternlayout
log4j.appender.console.layout.conversionpattern=[%-5p]%d (%r)--[%t]%l:%m%x%n

# log file (logFile)
Log4j.appender.logfile=org.apache.log4j.fileappender
Log4j.appender.logfile.threshold=debug
log4j.appender.logfile.immediateflush=true
log4j.appender.logfile.append=true
log4j.appender.logfile.file=d:/logs/log.log4j
Log4j.appender.logfile.layout=org.apache.log4j.patternlayout
log4j.appender.logfile.layout.conversionpattern=[%-5p]%d (%r)--[%t]%l:%m%x%n
# Rollback file (rollingfile)
Log4j.appender.rollingfile=org.apache.log4j.rollingfileappender
Log4j.appender.rollingfile.threshold=debug
log4j.appender.rollingfile.immediateflush=true
log4j.appender.rollingfile.append=true
log4j.appender.rollingfile.file=d:/logs/log.log4j
log4j.appender.rollingfile.maxfilesize=200kb
log4j.appender.rollingfile.maxbackupindex=50
Log4j.appender.rollingfile.layout=org.apache.log4j.patternlayout
log4j.appender.rollingfile.layout.conversionpattern=[%-5p]%d (%r)--[%t]%l:%m%x%n
# Roll Back log files periodically (Dailyfile)
Log4j.appender.dailyfile=org.apache.log4j.dailyrollingfileappender
Log4j.appender.dailyfile.threshold=debug
log4j.appender.dailyfile.immediateflush=true
log4j.appender.dailyfile.append=true
log4j.appender.dailyfile.file=d:/logs/log.log4j
log4j.appender.dailyfile.datepattern= '. ' YYYY-MM-DD
Log4j.appender.dailyfile.layout=org.apache.log4j.patternlayout
log4j.appender.dailyfile.layout.conversionpattern=[%-5p]%d (%r)--[%t]%l:%m%x%n
# applied to 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 Factor 5
Log4j.appender.socket.layout=org.apache.log4j.patternlayout
log4j.appender.socket.layout.conversionpattern=[%-5p]%d (%r)--[%t]%l:%m%x%n
# Log Factor 5 Appender
Log4j.appender.lf5_appender=org.apache.log4j.lf5.lf5appender
Log4j.appender.LF5_APPENDER. maxnumberofrecords=2000
# Send log to specified message
Log4j.appender.mail=org.apache.log4j.net.smtpappender
Log4j.appender.mail.threshold=fatal
log4j.appender.mail.buffersize=10
log4j.appender.mail.From = [email protected]
log4j.appender.mail.smtphost=mail.com
log4j.appender.mail.subject=log4j Message
log4j.appender.mail.to= [email protected]
Log4j.appender.mail.layout=org.apache.log4j.patternlayout
log4j.appender.mail.layout.conversionpattern=[%-5p]%d (%r)--[%t]%l:%m%x%n
# Apply to 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 (' =[%-5p]%d (%r)--[%t]%l:%m%x%n ')
Log4j.appender.database.layout=org.apache.log4j.patternlayout
log4j.appender.database.layout.conversionpattern=[%-5p]%d (%r)--[%t]%l:%m%x%n

# Custom 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 = [email protected]
Log4j.appender.im.layout=org.apache.log4j.patternlayout
log4j.appender.im.layout.conversionpattern=[%-5p]%d (%r)--[%t]%l:%m%x%n

log4j output logs to different files by level

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.