In Java projects, the general use of the log framework Log4j,logback, in contrast to the use of both I prefer to use logback, because in my opinion logback configuration more simple and efficient, The completeness of the log records in the project can help us to better analyze and solve the problems on the line, and facilitate the quick location of the problem.
Several scenes used in the project: Log the SQL output of the background, record the execution of the main business, the alarm system needs to monitor the different logs, need to do the separation of the log.
No more nonsense, the following is the configuration of Logback.xml:
<?xml version= "1.0" encoding= "UTF-8"?> <configuration> <contextname>native-business</ contextname> <!--<property file= "/APPLICATION.PROPERTIES.VM"/>--> <!--log save path to Tomcat under logs below the M Obilelog folder, Logback automatically creates folders so that you can output log files--<!--<substitutionproperty name= "logbase" value= "${ catalina.base}/logs/"/>--> <!--<property name=" Logback.logpath "value=" ${catalina.base}/logs/"/>-- > <property name= "Logback.logpath" value= "${catalina.base}/logs/project-web/"/> <!--<property name = "Logback.fixedWindowRollingPolicy.minIndex" value= "1"/> <property name= " Logback.fixedWindowRollingPolicy.maxIndex "value=" "/> <property name=" Logback. Sizebasedtriggeringpolicy.maxfilesize "value=" 1MB "/>--> <property name=" logbase "value=" ${logback.logPath } "/> <!--this is to configure the output file--<jmxconfigurator/> <appender name=" STDOUT "class=" Ch.qos.logbacK.core.consoleappender "> <!--encoder default configuration is Patternlayoutencoder---<encoder> & lt;pattern>%date [%thread]%-5level%logger{80} [%file:%line]%msg%n</pattern> </encoder> </ appender> <appender name= "FILE" class= "Ch.qos.logback.core.rolling.RollingFileAppender" > <!--current L OG file name-<file>${logbase}project.log</file> <encoder> <pattern>%da Te [%thread]%-5level%logger{80} [%file:%line]%msg%n</pattern> <!--<pattern>%p%t%c-%m%n& Lt;/pattern>-</encoder> <rollingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRol Lingpolicy "> <fileNamePattern>${logbase}project.%d{yyyy-MM-dd}.log</fileNamePattern> &L t;/rollingpolicy> <!--<triggeringpolicy class= "Ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy" &G
T <maxfilEsize>${logback.
Sizebasedtriggeringpolicy.maxfilesize}</maxfilesize> </triggeringPolicy>--> </appender> <appender name= "TMT" class= "Ch.qos.logback.core.rolling.RollingFileAppender" > <filter class= "ch.qos.l Ogback.classic.filter.LevelFilter "> <level>INFO</level> <onmatch>accept</o
Nmatch> <onMismatch>DENY</onMismatch> </filter> <!--current log file name-- <file>${logbase}tmt.log</file> <encoder> <pattern>%date [%thread]%-5le Vel%logger{80} [%file:%line]%msg%n</pattern> <!--<pattern>%p%t%c-%m%n</pattern>--
> </encoder> <rollingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" > <fileNamePattern>${logbase}tmt.%d{yyyy-MM-dd}.log</fileNamePattern> <!--<minindex& gt;1≪/minindex> <maxIndex>200</maxIndex>--> </rollingPolicy> <!--< ; Triggeringpolicy class= "Ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy" > <maxfilesize>${logba Ck.
Sizebasedtriggeringpolicy.maxfilesize}</maxfilesize> </triggeringPolicy>--> </appender> <appender name= "Tmterror" class= "Ch.qos.logback.core.rolling.RollingFileAppender" > <filter class= "ch.q Os.logback.classic.filter.LevelFilter "> <level>ERROR</level> <onmatch>accept& Lt;/onmatch> <onMismatch>DENY</onMismatch> </filter> <!--current log file name--&
Gt <file>${logbase}tmt_error.log</file> <encoder> <pattern>%date [%thread]%-5lev El%logger{80} [%file:%line]%msg%n</pattern> <!--<pattern>%p%t%c-%m%n</pattern>--&
Gt </encoder> <rollingpolicy class= "Ch.qos.logback.core.rolling.TimeBasedRollingPolicy" > <filenamepattern>${logbase}tmt_error.%d{yyyy-mm-dd}.log</