[英]Configure Unitils Log
I want to configure the log level of Unitils because I don't want to show Information traces when I run my tests. 我想配置Unitils的日志级别,因为我不想在运行测试时显示信息跟踪。 The tests run with Unitils through Spring:
这些测试通过Spring与Unitils一起运行:
@RunWith(UnitilsJUnit4TestClassRunner.class)
@SpringApplicationContext("testConfig.xml")
@Transactional(value = TransactionMode.ROLLBACK)
public class ContractorServiceIT
I configure logs using logback: 我使用logback配置日志:
<property name="pathfile" value="${catalina.base}/logs" />
<appender name="FILE"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${pathfile}/health-safety-web-test.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>${pathfile}/archived/health-safety-web-test.%d{yyyy-MM-dd}.log</FileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{100} - %msg%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{100} - %msg%n</pattern>
</encoder>
</appender>
<logger name="org.springframework" level="WARN"/>
<logger name="org.hibernate" level="WARN" />
<logger name="org.hibernate.cache" level="ERROR" />
<logger name="org.hibernate.SQL" level="WARN"/>
<logger name="net.sf.ehcache" level="WARN"/>
<logger name="com.vaadin.spring" level="WARN"/>
<logger name="org.vaadin.spring" level="WARN"/>
<logger name="org.atmosphere" level="WARN"/>
<logger name="org.dbunit" level="ERROR"/>
<logger name="org.unitils" level="ERROR"/>
<logger name="es.cic" level="INFO"/>
<root level="WARN">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
When I run the tests, in the file health-safety-web-test.log doesn't appear Info logs, but eclipse and console (mvn install) show those logs. 当我运行测试时,文件health-safety-web-test.log中没有出现信息日志,但是eclipse和控制台(mvn install)显示了这些日志。
This is an example of the logs I don't want to show: 这是我不想显示的日志示例:
feb 27, 2017 9:07:38 AM org.unitils.core.ConfigurationLoader loadCustomConfiguration
ADVERTENCIA: No custom configuration file unitils.properties found.
feb 27, 2017 9:07:38 AM es.cic.viesgo.core.commons.testing.PropertiesDataSourceFactory createDataSource
INFORMACIÓN: You are running with Spring Security Core 4.0.4.RELEASE
feb 27, 2017 9:07:39 AM org.springframework.security.config.SecurityNamespaceHandler <init>
INFORMACIÓN: Spring Security 'config' module version is 4.0.4.RELEASE
feb 27, 2017 9:07:39 AM org.springframework.security.config.method.GlobalMethodSecurityBeanDefinitionParser parse
Any idea? 任何想法?
The problem was that Unitils uses commons-logging
to print logs, and I am using SLF4J
in my project. 问题是Unitils使用
commons-logging
打印日志,而我在项目中使用SLF4J
。 I solved the problem changing the dependency of SLF4J
我解决了更改
SLF4J
依赖项的问题
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
for 对于
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
And now Unitils logs (and any other libreries which uses commons-logging
) can be configured in the logback.xml
file. 现在,可以在
logback.xml
文件中配置Unitils日志(以及使用commons-logging
任何其他库)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.