测试时的 log4j 配置仅显示错误
log4j config when testing to show only Errors
我有一个 Spring 应用程序,我在其中使用 eclipselink 和 dbunit 进行测试 我在 [=25= 上创建了这个 log4j.xml 文件]/
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true"
xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<level value="ERROR" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
但是当我 运行 测试时,我在控制台中看到很多消息,不仅仅是错误消息:
T E S T S
-------------------------------------------------------
Running com.pastis.services.config.TestConfig
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
log4j: reset attribute= "false".
log4j: Threshold ="null".
log4j: Level value for root is [ERROR].
log4j: root level set to ERROR
log4j: Class name: [org.apache.log4j.ConsoleAppender]
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n].
log4j: Adding appender named [console] to category [root].
[EL Fine]: 2020-09-30 17:08:19.045--Thread(Thread[main,5,main])--Configured server platform: org.eclipse.persistence.platform.server.wls.WebLogicPlatform
[EL Config]: 2020-09-30 17:08:19.298--ServerSession(142103421)--Thread(Thread[main,5,main])--The access type for the persistent class [class com.pastis.FactureCommentType] is set to [FIELD].
[EL Config]: 2020-09-30 17:08:19.335--ServerSession(142103421)--Thread(Thread[main,5,main])--The target entity (reference) class for the one to many mapping element [field factureComments] is being defaulted to: class com.pastis.mode
[EL Config]: 2020-09-30 17:08:19.336--ServerSession(142103421)--Thread(Thread[main,5,main])--The access type for the persistent class [class com.pastis.model.inscriptions.Institution] is set to [FIELD].
[EL Config]: 2020-09-30 17:08:19.336--ServerSession(142103421)--Thread(Thread[main,5,main])--The target entity (reference) class for the one to many mapping element [field personneAffectations] is being defaulted to: class eu.europa.ec.oi
[EL Fine]: 2020-09-30 17:08:58.808--ServerSession(142103421)--Connection(1923962747)--Thread(Thread[main,5,main])--SELECT COUNT(EXERCICE_ID) FROM EXERCICE
这是我的 /src/test/java/META-INF/persistence.xml
文件:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="pastis-server-services">
<properties>
<property name="eclipselink.logging.level" value="OFF"/>
<property name="eclipselink.logging.parameters" value="false"/>
<property name="eclipselink.weaving" value="static" />
<property name="eclipselink.logging.level.sql" value="OFF" />
<property name="eclipselink.logging.level.cache" value="OFF" />
</properties>
</persistence-unit>
</persistence>
在我的专家中 pom.xml:
<properties>
<eclipselink.showSql>false</eclipselink.showSql>
<eclipselink.logging.level>OFF</eclipselink.logging.level>
<eclipselink.logging.level.sql>OFF</eclipselink.logging.level.sql>
</properties>
日志级别配置包含在persistence.xml中持久化单元的定义中,
添加这个:
<property name="eclipselink.logging.level" value="OFF"/>
<property name="eclipselink.logging.parameters" value="false"/>
<property name="eclipselink.weaving" value="static" />
<property name="eclipselink.logging.level.sql" value="OFF" />
<property name="eclipselink.logging.level.cache" value="OFF" />
wiki:wiki.eclipse.org/EclipseLink/Examples/JPA/Logging 描述了 EclipseLink 中的日志记录。在这种情况下,您似乎在 Weblogic 服务器上(由配置的服务器平台 WebLogicPlatform 日志消息确定),并且如果使用容器管理的持久性,则可能会将其自己的记录器注入持久性单元 - 您需要使用 WebLogic控制台更改日志记录设置。
您可以通过添加以下内容来防止这种情况:
<property name="eclipselink.logging.logger" value="DefaultLogger"/>
到 persistence.xml,这将使 EclipseLink 使用自己的日志记录,这将使用您已经配置的设置。
我有一个 Spring 应用程序,我在其中使用 eclipselink 和 dbunit 进行测试 我在 [=25= 上创建了这个 log4j.xml 文件]/
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration debug="true"
xmlns:log4j='http://jakarta.apache.org/log4j/'>
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern"
value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n" />
</layout>
</appender>
<root>
<level value="ERROR" />
<appender-ref ref="console" />
</root>
</log4j:configuration>
但是当我 运行 测试时,我在控制台中看到很多消息,不仅仅是错误消息:
T E S T S
-------------------------------------------------------
Running com.pastis.services.config.TestConfig
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
log4j: reset attribute= "false".
log4j: Threshold ="null".
log4j: Level value for root is [ERROR].
log4j: root level set to ERROR
log4j: Class name: [org.apache.log4j.ConsoleAppender]
log4j: Parsing layout of class: "org.apache.log4j.PatternLayout"
log4j: Setting property [conversionPattern] to [%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n].
log4j: Adding appender named [console] to category [root].
[EL Fine]: 2020-09-30 17:08:19.045--Thread(Thread[main,5,main])--Configured server platform: org.eclipse.persistence.platform.server.wls.WebLogicPlatform
[EL Config]: 2020-09-30 17:08:19.298--ServerSession(142103421)--Thread(Thread[main,5,main])--The access type for the persistent class [class com.pastis.FactureCommentType] is set to [FIELD].
[EL Config]: 2020-09-30 17:08:19.335--ServerSession(142103421)--Thread(Thread[main,5,main])--The target entity (reference) class for the one to many mapping element [field factureComments] is being defaulted to: class com.pastis.mode
[EL Config]: 2020-09-30 17:08:19.336--ServerSession(142103421)--Thread(Thread[main,5,main])--The access type for the persistent class [class com.pastis.model.inscriptions.Institution] is set to [FIELD].
[EL Config]: 2020-09-30 17:08:19.336--ServerSession(142103421)--Thread(Thread[main,5,main])--The target entity (reference) class for the one to many mapping element [field personneAffectations] is being defaulted to: class eu.europa.ec.oi
[EL Fine]: 2020-09-30 17:08:58.808--ServerSession(142103421)--Connection(1923962747)--Thread(Thread[main,5,main])--SELECT COUNT(EXERCICE_ID) FROM EXERCICE
这是我的 /src/test/java/META-INF/persistence.xml
文件:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="pastis-server-services">
<properties>
<property name="eclipselink.logging.level" value="OFF"/>
<property name="eclipselink.logging.parameters" value="false"/>
<property name="eclipselink.weaving" value="static" />
<property name="eclipselink.logging.level.sql" value="OFF" />
<property name="eclipselink.logging.level.cache" value="OFF" />
</properties>
</persistence-unit>
</persistence>
在我的专家中 pom.xml:
<properties>
<eclipselink.showSql>false</eclipselink.showSql>
<eclipselink.logging.level>OFF</eclipselink.logging.level>
<eclipselink.logging.level.sql>OFF</eclipselink.logging.level.sql>
</properties>
日志级别配置包含在persistence.xml中持久化单元的定义中,
添加这个:
<property name="eclipselink.logging.level" value="OFF"/>
<property name="eclipselink.logging.parameters" value="false"/>
<property name="eclipselink.weaving" value="static" />
<property name="eclipselink.logging.level.sql" value="OFF" />
<property name="eclipselink.logging.level.cache" value="OFF" />
wiki:wiki.eclipse.org/EclipseLink/Examples/JPA/Logging 描述了 EclipseLink 中的日志记录。在这种情况下,您似乎在 Weblogic 服务器上(由配置的服务器平台 WebLogicPlatform 日志消息确定),并且如果使用容器管理的持久性,则可能会将其自己的记录器注入持久性单元 - 您需要使用 WebLogic控制台更改日志记录设置。
您可以通过添加以下内容来防止这种情况:
<property name="eclipselink.logging.logger" value="DefaultLogger"/>
到 persistence.xml,这将使 EclipseLink 使用自己的日志记录,这将使用您已经配置的设置。