简体   繁体   English

Spring Restful Web服务日志记录

[英]spring restful web service logging

I implemented Spring RESTful Web Service using this tutorial: https://spring.io/guides/gs/rest-service/ . 我使用以下教程实现了Spring RESTful Web服务: https : //spring.io/guides/gs/rest-service/ I added dependencies for log4j in pom.xml and log4j.properties file in src/main/resources folder. 我在pom.xml中添加了log4j的依赖关系,并在src / main / resources文件夹中添加了log4j.properties文件。 Now I expect logging to be done into log file as stated inthe log4j.properties file instead of to STDOUT. 现在,我希望将日志记录到log4j.properties文件中所述的日志文件中,而不是STDOUT中。 However, logging goes only to STDOUT. 但是,日志记录仅进入STDOUT。 How can I fix tis to print log messages to log file? 如何修复tis以将日志消息打印到日志文件?

By default Spring Boot uses LogBack as logging framework. 默认情况下,Spring Boot使用LogBack作为日志框架。 If you want to configure Log4J, follow this configuration . 如果要配置Log4J,请遵循此配置 You need to exclude Spring Boot's logging module (containing LogBack dependency) and include Spring boot started for log4j. 您需要排除Spring Boot的日志记录模块(包含LogBack依赖项),并包括为log4j启动的Spring boot。

BTW, log4j is ancient technology, consider moving to logback or log4j2 顺便说一句,log4j是古老的技术,请考虑移至logback或log4j2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM