log4g简单配置控制台配置,
轻松无压力java日志配置轻松完成以下是代码详细配置
虽然我也是新手
#ConsoleAppender log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}%m%n #FileAppender log4j.appender.file=org.apache.log4j.FileAppender log4j.appender.file.File=file.log log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}%m%n #RollingFileAppender log4j.appender.rollfile=org.apache.log4j.RollingFileAppender log4j.appender.rollfile.File=rollfile.log log4j.appender.rollfile.MaxBackupIndex=3 log4j.appender.rollfile.MaxFileSize=2KB log4j.appender.rollfile.layout=org.apache.log4j.PatternLayout log4j.appender.rollfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}%m%n #DailyRollingFileAppender log4j.appender.dailyfile=org.apache.log4j.DailyRollingFileAppender log4j.appender.dailyfile.File=dailyfile.log log4j.appender.dailyfile.layout=org.apache.log4j.PatternLayout log4j.appender.dailyfile.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}%m%n log4j.appender.dailyfile.DatePattern=’.'yyyy-MM-dd-HH-mm’.log’ #JDBCAppender(DATA) #log4j.appender.db=org.apache.log4j.jdbc.JDBCAppender #log4j.appender.db.URL=jdbc:jtds:sqlserver://localhost:1433;databaseName=logdb #log4j.appender.db.Driver=net.sourceforge.jtds.jdbc.Driver #log4j.appender.db.User=sa #log4j.appender.db.Password=123 #log4j.appender.db.Sql=insert into mylog values(‘%d{yyyy-MM-dd HH:mm:ss}’,'%m’) #log4j.appender.db.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}%m%n #log4j.appender.db.layout=org.apache.log4j.PatternLayout log4j.rootLogger=debug,stdout,file,rollfile,dailyfile,db #JDBCAppender(DATA) #log4j.appender.db=org.apache.log4j.jdbc.JDBCAppender #log4j.appender.db.URL=jdbc:jtds:sqlserver://localhost:1433;databaseName=logdb #log4j.appender.db.Driver=net.sourceforge.jtds.jdbc.Driver #log4j.appender.db.User=root #log4j.appender.db.Password=123456 #log4j.appender.db.Sql=insert into mylog values(‘%d{yyyy-MM-dd HH:mm:ss}’,'%m’) #log4j.appender.db.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}%m%n #log4j.appender.db.layout=org.apache.log4j.PatternLayout log4j.properties package com.sec.log4j; import org.apache.log4j.Logger; public class Test { /** * Logger for this class */ private static final Logger logger = Logger.getLogger(Test.class); public static void main(String[] args) { for(int i=0;i<1000;i++) { logger.debug("1111"); } } } package com.sec.log4j; import org.apache.log4j.Logger; public class TestLog4j { private static Logger logger=Logger.getRootLogger(); public static void main(String[] args) { logger.debug("debug11"); logger.info("info11"); logger.warn("warn11"); logger.error("error111"); } }