Logbacklogback log configuration and log separation

Source: Internet
Author: User

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&Lt;/minindex> <maxIndex>200</maxIndex>--> </rollingPolicy> <!--&lt ; 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</

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.