- Common logging framework
Laog4j:
Log4j2:
SLF4J: log output interfaces, dependent on other underlying logging framework
Logback:
Apache Commons Logging: slf4j and the like, an output interface is the log, log frameworks rely on third parties
java.util.logging.Logger: JDK comes with the system log
Generally used in the project as a log slf4j abstract, so that later replace the log framework system, then you need only replace the JAR, without modifying the code.
- slf4j
slf4j just a log output to provide a unified interface for the Java program, logging is not a specific implementation, such as JDBC, like it, is just a rule only, so slf4j alone will not work,
The logs must be used with other specific implementations, such as log4j or log4j2
- slf4j + log4j
Required jar: log4j-xxx.jar slf4j-api-xxx.jar slf4j-log4j12-xx.jar (bridging package)
log4j log output level:
TRACE > DEBUG > INFO > WARN > ERROR > FATAL
But note that there is no FATAL level slf4j
com.basic.work.log Package; Import org.slf4j.Logger; Import org.slf4j.LoggerFactory; / * * * * + log4j combination SLF4J * required jar: log4j-xxx.jar slf4j-api -xxx.jar slf4j xx.jar--log4j12 * * slf4j just a log output to provide a unified interface for the Java program, logging is not a specific implementation, * it such as JDBC, it is only a rule, it is not working alone slf4j and * must be used with other specific log implementation, such as log4j or log4j2 * output levels * log: * the TRACE> DEBUG> INFO> WARN> ERROR> FATAL * * Note slf4j no rating FATAL * @author chenzhubing * * / public class Log4j { Private static Final Logger LoggerFactory.getLogger = log (Log4j. class); public static void main(String[] args) { log.info("hekk"); log.warn("warn"); log.error("sssss"); log.trace("trace"); log.debug("debug"); } }
- log4j.properties
= Log4j.rootLogger the TRACE, XXX, yyy, ZZZ, CCC #xxx stands for console log4j.appender.xxx = org.apache.log4j.ConsoleAppender tells that #PatternLayout flexibility to the information string specified level and pattern layout log information SimpleLayout log4j.appender .xxx.layout = Org.apache.log4j.PatternLayout log4j.appender.xxx.layout.ConversionPattern = (% R & lt MS) [% T]% -5p:% C% X #% m:% m% n- #yyy representative file log4j.appender.yyy = org.apache.log4j.FileAppender log4j.appender.yyy.layout = Org.apache.log4j.PatternLayout log4j.appender.yyy.layout.ConversionPattern = (% R & lt MS) [% T]% -5p :% C% X #% m:% m% n- log4j.appender.yyy.File = F: /FileAppender.log #zzz representatives DailyRollingFileAppender create a file every day log4j.appender.zzz = org.apache.log4j.DailyRollingFileAppender log4j.appender.zzz.layout = org.apache.log4j.PatternLayout log4j.appender.zzz.layout.ConversionPattern = ( MS R & lt%) [% T]% -5p:% C% X #% m:% m% n- log4j.appender.zzz.File = F: / log4j- DailyRollingFileAppender.log # defaults to true appended to the file; to false cover the original file log4j.appender.zzz.Append = false #ccc representatives RollingFileAppender file reaches the specified size, create a new file log4j.appender.ccc = org.apache.log4j.RollingFileAppender log4j.appender.ccc.layout =Org.apache.log4j.PatternLayout log4j.appender.ccc.layout.ConversionPattern = (% R & lt MS) [% T]% -5p:% C% X #% M:% m% n- log4j.appender.ccc.File = F : / log4j- RollingFileAppender.log maximum size # specified file exceeds the maximum size will generate a new file [file size corresponds to a maximum time of occurrence of the oldest, smallest file size corresponds to the most recent time occurred] log4j.appender.ccc .MaxFileSize = 50kB # retain up to 50 most recent occurrence of the file log4j.appender.ccc.MaxBackupIndex = 50