【发布时间】:2015-09-12 05:00:35
【问题描述】:
我想在我的项目中添加日志记录(用于控制台),以便在 Spring Boot 中进行测试。 我有我的测试:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {TestConfig.class})
public class MyTest {
private final static org.slf4j.Logger LOGGER = LoggerFactory.getLogger(MyTest.class);
@Autowired
public UserDao userDao;
@Test
public void test1() {
LOGGER.info("info test");
LOGGER.debug("debug test");
}
}
和我的测试配置:
@Configuration
@EnableJpaRepositories("example.dao")
@ComponentScan(basePackageClasses = { MyServiceImpl.class})
@EntityScan({"example.model"})
@Import({DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class TestConfig {
}
我在test/resource 中创建了一个application.properties 文件。 Gradle 将我的资源文件夹视为测试资源。
这是我的application.properties:
logging.level.= INFO
logging.level.tests.= INFO
logging.level.org.hibernate= INFO
logging.level.org.springframework= INFO
logging.level.org.apache.cxf= INFO
但是当我运行测试时,我有:
16:59:17.593 [main] INFO tests.MyTest - info test
16:59:17.594 [main] DEBUG tests.MyTest - debug test
在控制台中。为什么?
我只设置了'INFO'(logging.level.= INFO)。为什么'DEBUG' 在控制台中?怎么能设置成'INFO'?
【问题讨论】:
-
logging.level和logging.level.tests末尾的点字符正常吗?
标签: java testing logging spring-boot