0

I want to configure the log level of Unitils because I don't want to show Information traces when I run my tests. The tests run with Unitils through Spring:

@RunWith(UnitilsJUnit4TestClassRunner.class)
@SpringApplicationContext("testConfig.xml")
@Transactional(value = TransactionMode.ROLLBACK)
public class ContractorServiceIT

I configure logs using 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.

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?

4

1 回答 1

0

问题是 Unitils 用于commons-logging打印日志,而我正在SLF4J我的项目中使用。我解决了改变依赖关系的问题SLF4J

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
</dependency>

为了

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jcl-over-slf4j</artifactId>
</dependency>

commons-logging现在可以在logback.xml文件中配置Unitils 日志(以及任何其他使用.

于 2017-02-28T10:14:11.587 回答