2

寻找如何在 Spring Boot 应用程序中配置 slf4j 的方式:

我在我的 application.properties 中添加了这个:

logging.level.org.springframework.web=DEBUG
logging.file=book.log
logging.level.*=DEBUG

我有这个控制器:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Controller
@RequestMapping("/book")
public class BookController {

    private static final Logger logger = LoggerFactory.getLogger(BookController.class);

@RequestMapping(value={ "/list"}, method = { RequestMethod.GET})
    public String bookList(Model model, HttpServletRequest request) throws DataAccessException, SQLException {

        logger.debug("testing...");

}
}

但是我的消息没有记录在文件中,但是还有其他消息:

...
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'org.springframework.boot.autoconfigure.web.MultipartAutoConfiguration': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'multipartConfigElement': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'multipartResolver': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'spring.http.multipart-org.springframework.boot.autoconfigure.web.MultipartProperties': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'serverProperties': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'duplicateServerPropertiesDetector': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration$RestTemplateConfiguration': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'restTemplateBuilder': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'org.springframework.boot.autoconfigure.web.WebClientAutoConfiguration': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'org.springframework.boot.devtools.autoconfigure.LocalDevToolsAutoConfiguration$RestartConfiguration': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'classPathFileSystemWatcher': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'classPathRestartStrategy': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'hateoasObjenesisCacheDisabler': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'fileSystemWatcherFactory': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'org.springframework.boot.devtools.autoconfigure.LocalDevToolsAutoConfiguration$LiveReloadConfiguration': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'liveReloadServer': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'optionalLiveReloadServer': no URL paths identified
2017-03-26 08:13:49.768 DEBUG 2426 --- [restartedMain] o.s.w.s.h.BeanNameUrlHandlerMapping      : Rejected bean name 'org.springframework.boot.devtools.autoconfigure.
...
4

2 回答 2

0

尝试使用

logging.level.*=DEBUG

当您指定具有日志记录级别的包名称时,它将仅适用于该包。您可以定义根记录器或对所有包使用 *。

于 2017-03-26T08:52:49.173 回答
0

即使我遇到了这个问题,添加 logging.level.*=DEBUG 也没有帮助。

你可以试试这个:

  1. logging.level.root = 调试

  2. logging.level.package_name=DEBUG 示例:logging.level.com.example.controller=DEBUG

于 2017-07-31T07:44:08.597 回答