Logback column used in the project

Source: Internet
Author: User
<? XML version = "1.0" encoding = "UTF-8"?> <Configuration> <appender name = "activity" class = "ch. qoS. logback. core. rolling. rollingfileappender "> <File> log/activity. log </File> <encoder charset = "UTF-8"> <pattern> % date | % MSG % n </pattern> </encoder> <rollingpolicy class = "ch. qoS. logback. core. rolling. timebasedrollingpolicy "> <filenamepattern> log/activity. log-% d {yyyy-mm-dd} </filenamepattern> <! -- Retention days/hours --> <maxhistory> 30 </maxhistory> </rollingpolicy> </appender> <appender name = "sys" class = "ch. qoS. logback. core. rolling. rollingfileappender "> <! -- Log output type --> <File> log/sys. Log </File> <encoder charset = "UTF-8"> <! -- Output formatting --> <pattern> % date | % thread | % level | % F-> % M | % MSG % n </pattern> </encoder> <! -- Critical value filter: filters out logs with lower levels --> <filter class = "ch. qoS. logback. classic. filter. thresholdfilter "> <level> info </level> </filter> <rollingpolicy class =" ch. qoS. logback. core. rolling. timebasedrollingpolicy "> <! -- Log migration method (rolling Policy) --> <filenamepattern> log/sys. log-% d {yyyy-mm-dd-hh} </filenamepattern> </rollingpolicy> </appender> <appender name = "stdout" class = "ch. qoS. logback. core. consoleappender "> <encoder charset =" UTF-8 "> <pattern> % date | % thread | % level | % F-> % M | % MSG % n </pattern> </ encoder> <filter class = "ch. qoS. logback. classic. filter. thresholdfilter "> <level> info </level> </filter> </appender> <! -- Additivity = "false" indicates not to pass --> <logger name = "activity" level = "debug" additivity = "false"> <appender-ref = "activity"/> </logger> <! -- Root is the default logger. The log output is first controlled by the logger level, and then controlled by the appender filter --> <root level = "debug"> <! -- Default logs are output in two ways --> <appender-ref = "stdout"/> <appender-ref = "sys"/> </root> </configuration>

 

Reference the jar package:

Logback-classic-1.1.1.jar logback-core-1.1.1.jar slf4j-api-1.6.6.jar

 

Java code:

package log_test;import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class Test {        private static final Logger log = LoggerFactory.getLogger(Test.class);    private static Logger log2 = LoggerFactory.getLogger("ACTIVITY");        public static void main(String[] args) {                log.info(System.currentTimeMillis()+"");        log.error(System.currentTimeMillis()+"");        log.debug(System.currentTimeMillis()+"");                log2.info(System.currentTimeMillis()+" ACTIVITY");        log2.error(System.currentTimeMillis()+" ACTIVITY");        log2.debug(System.currentTimeMillis()+" ACTIVITY");            }}

 

Logback column used in the project

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.