SPRINGMVC integrated slf4j, log4j record text log

Source: Internet
Author: User

First, configure the Pom.xml
123456789101112131415161718192021222324252627282930313233343536 <properties>        <slf4j.version>1.7.12</slf4j.version>    </properties> <!-- 日志 -->        <dependency>            <groupId>org.slf4j</groupId>            <artifactId>jcl-over-slf4j</artifactId>            <version>${slf4j.version}</version>        </dependency>        <dependency>            <groupId>org.slf4j</groupId>            <artifactId>slf4j-api</artifactId>            <version>${slf4j.version}</version>        </dependency>        <dependency>            <groupId>org.slf4j</groupId>            <artifactId>slf4j-log4j12</artifactId>            <version>${slf4j.version}</version>        </dependency>        <dependency>            <groupId>log4j</groupId>            <artifactId>log4j</artifactId>            <version>1.2.17</version>        </dependency>        <dependency>            <groupId>commons-logging</groupId>            <artifactId>commons-logging</artifactId>            <version>1.2</version>        </dependency>    <dependency>            <groupId>org.apache.commons</groupId>            <artifactId>commons-lang3</artifactId>            <version>3.1</version>        </dependency>


Second, resource folder add Log4j.properties

1234567891011121314151617181920212223 # Output pattern : date [thread] priority category - messagelog4j.rootLogger=INFO, Console,RollingFile#Console(write to console)log4j.appender.Console=org.apache.log4j.ConsoleAppenderlog4j.appender.Console.layout=org.apache.log4j.PatternLayoutlog4j.appender.Console.layout.ConversionPattern=%d %-5p [%c] - %m%n  #RollingFile(write to file /logs/hr.log)log4j.appender.RollingFile=org.apache.log4j.DailyRollingFileAppenderlog4j.appender.RollingFile.File=C:/logs/hr.loglog4j.appender.RollingFile.layout=org.apache.log4j.PatternLayoutlog4j.appender.RollingFile.layout.ConversionPattern=%d %-5p [%c] - %m%nlog4j.logger.com.ibatis=DEBUG  log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=INFO  log4j.logger.com.ibatis.common.jdbc.ScriptRunner=INFO  log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=INFO  log4j.logger.java.sql.Connection=INFO  log4j.logger.java.sql.Statement=INFO  log4j.logger.java.sql.PreparedStatement=INFO  log4j.logger.java.sql.ResultSet=INFO


Third, write the log

123 protectedstatic Logger logger = LoggerFactory.getLogger(LoginSevice.class);logger.info("helloMvc-Service");


Springmvc consolidate slf4j, log4j record text 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.