IDEA??????????????????Log4j2+Slf4j??????????????????
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IDEA??????????????????Log4j2+Slf4j??????????????????相关的知识,希望对你有一定的参考价值。
?????????debug erro ?????? context inter war col nlog inf
?????????????????????????????????????????????????????????????????????????????????slf4j?????????????????????????????????log4j2???logback????????????????????????????????????????????????????????????????????????????????????slf4j?????????????????????????????????????????????????????????????????????????????????????????????log4j2????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????
- log4j2 2.8.1 + slf4j 1.7.25
- IntelliJ IDEA 2017.2.5
- maven 3.0.5
????????????
Step 1?????????maven??????
????????????<properties> ??????<slf4j.version>1.7.25</slf4j.version> ??????<log4j.version>2.8.2</log4j.version> ????????????</properties> ???????????????<dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-web</artifactId> <version>${log4j.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>${log4j.version}</version> </dependency>
Step 2?????????????????????
???????????????????????????resources?????????????????????????????????log4j2.xml??????????????????IDEA????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????web.xml??????????????????????????????
<context-param> <param-name>log4jConfiguration</param-name> <!-- ???????????????????????????????????????????????????????????? --> <param-value>classpath:conf/log4j2.xml</param-value> </context-param>
??????????????????log4j2.xml????????????????????????????????????????????????????????????????????????
<?xml version="1.0" encoding="utf-8"?> <!--???????????????TRACE < DEBUG < INFO < WARN < ERROR < FATAL,???????????????WARN????????????WARN????????????????????????--> <!-- status : ??????????????????log4j2???????????????????????????,???????????????,????????????trace???,?????????log4j2???????????????????????? monitorInterval : Log4j?????????????????????????????????????????????????????????, ???????????????????????????????????????300??????????????????????????? --> <Configuration status="ERROR" monitorInterval="300"> <!--<properties>--> <!--<property name="LOG_HOME">F:\logs</property>--> <!--<property name="ERROR_LOG_FILE_NAME">error</property>--> <!--</properties>--> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <!-- ???????????????Console???Appender --> <PatternLayout pattern="%d{HH:mm:ss} [%-5level] [%-10thread] %c{1} - %msg%n"/> <!-- ???????????????Pattern???Layout --> </Console> </Appenders> <!--??????logger??????????????????logger??????????????????appender???appender????????????--> <Loggers> <Root level="error"> <!-- ??????Root Logger --> <AppenderRef ref="Console"/> <!-- Root Logger???Appender?????????????????????Console --> </Root> <!--???????????????MainLogger???Logger?????????????????????info???info???????????????????????????????????? --> <Logger name="MainLogger" level="info" additivity="false"> <AppenderRef ref="Console"/> <!-- Root Logger???Appender?????????????????????Console --> </Logger> </Loggers> </Configuration>
Step 3??? ???Java???????????????slf4j?????????????????????
????????????Logger???????????????????????????????????????
@Controller public class MainController { // ??????log4j2.xml???????????????????????????MainLogger??????Logger // ???????????????????????????Logger??????????????????Logger??????????????????????????? private static final Logger log = LoggerFactory.getLogger("MainLogger"); @RequestMapping(value = "/test") public String test(){ log.info("info..."); log.debug("debug..."); log.warn("warn..."); log.error("error..."); return "test"; } }
以上是关于IDEA??????????????????Log4j2+Slf4j??????????????????的主要内容,如果未能解决你的问题,请参考以下文章