====== only log4j ====== # log4j.rootLogger = [ level ] , appenderName, appenderName, ... # level 是日志记录的优先级 # appenderName就是指定日志信息输出到哪个地方。您可以同时指定多个输出目的地。 log4j.rootLogger = debug,INFO,ERR # 日志记录类型(当前是滚动追加) log4j.appender.INFO = org.apache.log4j.RollingFileAppender # 文件名 log4j.appender.INFO.File = /tmp/log.log # 文件多大时滚动 log4j.appender.INFO.MaxFileSize = 100mb # 每次启动是追加还是覆盖,true 追加,false覆盖 log4j.appender.INFO.Append = true # 输出级别 log4j.appender.INFO.Threshold = info # 指定日志输出格式 log4j.appender.INFO.layout=org.apache.log4j.PatternLayout # 日志输出格式字段 log4j.appender.INFO.layout.ConversionPattern=%d-[HL] %p %t %c - %m%n log4j.appender.ERR = org.apache.log4j.RollingFileAppender log4j.appender.ERR.File = /tmp/error.log log4j.appender.ERR.MaxFileSize = 100mb log4j.appender.ERR.Append = true log4j.appender.ERR.Threshold = error log4j.appender.ERR.layout=org.apache.log4j.PatternLayout log4j.appender.ERR.layout.ConversionPattern=%d %p %t %c: %m%n #%m 输出代码中指定的消息 #%p  输出优先级,即DEBUG,INFO,WARN,ERROR,FATAL #%r  输出自应用启动到输出该log信息耗费的毫秒数 #%c  输出所属的类目,通常就是所在类的全名 #%t  输出产生该日志事件的线程名 #%d  输出日志时间点的日期或时间 #%你 换行 ====== slf4j + logback ====== mvn org.slf4j slf4j-api 1.7.12 ch.qos.logback logback-classic 1.1.2 ch.qos.logback logback-core 1.1.2 logback.xml System.out [%d{yyyy-MM-dd HH:mm:ss}] %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{120}) %M %L - %cyan(%msg%n) logs/app.log true %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %thread %logger{80} - %msg%n logs/app.%i.log 1 3 512MB 0 512 main import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Created by caj on 16/3/7. */ public class App { private static final Logger logger = LoggerFactory.getLogger(App.class.getName()); public static void main(String[] args) { logger.info("hello word"); } } ====== slf4j + log4j ====== mvn org.slf4j slf4j-api 1.7.12 org.slf4j slf4j-log4j12 1.7.5 log4j.properties log4j.rootLogger=info, ERR log4j.appender.ERR = org.apache.log4j.RollingFileAppender log4j.appender.ERR.File = /Users/caj/workdir/JavaProject/cc/error.log log4j.appender.ERR.MaxFileSize = 100mb log4j.appender.ERR.Append = true log4j.appender.ERR.Threshold = info log4j.appender.ERR.layout=org.apache.log4j.PatternLayout log4j.appender.ERR.layout.ConversionPattern=%d %p %t %c: %m%n main import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Created by caj on 16/3/7. */ public class App { private static final Logger logger = LoggerFactory.getLogger(App.class.getName()); public static void main(String[] args) { logger.info("hello word"); } }