<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.29</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.29</version>
</dependency>
log4j.properties 文件,放在resources下 (stdout和file 要和下面的保持一致,是大写都是大写,是小写都是小写) # log4j.rootLogger=WARN, stdout, file log4j.rootLogger=info,stdout,file log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%p][%C.%M()]: %m%n # Output to the File log4j.appender.file=org.apache.log4j.DailyRollingFileAppender log4j.appender.file.DatePattern='_'yyyy-MM-dd'.log' log4j.appender.file.File=./log/medium_system_api.log log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%p][%C.%M()]: %m%n
logging.properties 文件
# 下载地址: # https://github.com/undertow-io/undertow/blob/master/examples/src/main/resources/logging.properties # # JBoss, Home of Professional Open Source. # Copyright 2012 Red Hat, Inc., and individual contributors # as indicated by the @author tags. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # Additional logger names to configure (root logger is always configured) loggers=org.xnio.listener,org.xnio.ssl,org.apache,io.undertow.util.TestHttpClient # Root logger configuration logger.level=${test.level:INFO} logger.handlers=CONSOLE # Console handler configuration handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler handler.CONSOLE.properties=autoFlush,target handler.CONSOLE.target=SYSTEM_ERR handler.CONSOLE.level=ALL handler.CONSOLE.autoFlush=true handler.CONSOLE.formatter=PATTERN # The log format pattern formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter formatter.PATTERN.properties=pattern formatter.PATTERN.pattern=%d{HH:mm:ss,SSS} %-5p (%t) [%c] <%F:%L> %m%n logger.org.xnio.listener.level=DEBUG logger.org.xnio.ssl.level=DEBUG logger.org.apache.level=info logger.org.apache.useParentHandlers=false logger.io.undertow.util.TestHttpClient.level=info
类中引用:
import org.slf4j.Logger; import org.slf4j.LoggerFactory;
private static final Logger logger= LoggerFactory.getLogger(UserController.class);
如果以上都配置无误,日志还是不能输出, 打印出
System.out.println("log"+logger);
然后去具体定位出现问题的地方