质量保证金 |关闭到控制台的日志记录(例如 INFO c.q.q.a.ui.WebDriverCommandLogger - 命令:)

QAF | Switch off logging to console (Eg. INFO c.q.q.a.ui.WebDriverCommandLogger - command: )

我想关闭在 运行 期间发生的控制台日志记录。我尝试在“资源”文件夹内的 log4j.properties 中添加 log4j.rootCategory=OFF。我还看到一些答案要求如果配置在 运行 期间没有获取,则将 log4j.properties 移动到“src”文件夹中。我已经尝试了所有可能的解决方法。

即使有任何直接的 java 解决方案可用于关闭“INFO c.q.q.a.ui.WebDriverCommandLogger - 命令:”进入控制台也会有所帮助。

log4j.properties:

log4j.rootCategory=OFF
log4j.appender.console.Follow=true
#log4j.logger.com.qmetry.qaf=CONSOLE, LOGFILE
# Set the enterprise logger category to FATAL and its only appender to CONSOLE.
log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE

# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
#log4j.appender.CONSOLE.Follow=true

log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%c{1}] - %m%n

# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.LOGFILE=org.apache.log4j.FileAppender
log4j.appender.LOGFILE.File=${outputDir}/isfw.log
log4j.appender.LOGFILE.Append=true
log4j.appender.LOGFILE.Threshold=DEBUG
log4j.appender.LOGFILE.Follow=true
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.LOGFILE.layout.ConversionPattern=[%t] %d{HH:mm:ss,SSS} %-5p [%c] %m%n
#%-4r [%t] %-5p %c %x - %m%n

log4j.logger.com.qmetry.qaf.automation.integration=resultUpdationLog

# LOGFILE is set to be a File appender using a PatternLayout.
log4j.appender.resultUpdationLog=org.apache.log4j.FileAppender
log4j.appender.resultUpdationLog.File=resultUpdation.log
log4j.appender.resultUpdationLog.Append=true
log4j.appender.resultUpdationLog.Threshold=INFO
log4j.appender.resultUpdationLog.layout=org.apache.log4j.PatternLayout
log4j.appender.resultUpdationLog.layout.ConversionPattern=%-6r [%t] %-5p %c %x - %m%n

log4j.additivity.com.qmetry.qaf.automation.step=false
log4j.logger.com.qmetry.qaf.automation.step=DEBUG, SCENARIOLOGFILE
log4j.appender.SCENARIOLOGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.SCENARIOLOGFILE.File=${outputDir}/scenario.log
log4j.appender.SCENARIOLOGFILE.Append=true
log4j.appender.SCENARIOLOGFILE.Threshold=DEBUG
log4j.appender.SCENARIOLOGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.SCENARIOLOGFILE.layout.ConversionPattern=%d{HH:mm:ss} %m%n

log4j.logger.com.qmetry.qaf.automation.ws=DEBUG, file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.file=${outputDir}/ws.log
log4j.appender.file.MaxFileSize=1GB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.conversionPattern=%d{[dd.MM.yyyy] [HH:mm:ss]} %p [%t] %c (%F:%L) - %m%n

Maven - pom.xml

<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.qmetry</groupId>
    <artifactId>qaf-blank-project-maven</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>qaf-blank-project-maven</name>
    <url>http://maven.apache.org</url>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <testSuiteFile>config/testrun_config.xml</testSuiteFile>
        <sourceVersion>1.8</sourceVersion>
        <targetVersion>1.8</targetVersion>
        <qaf.version>3.0.0</qaf.version>
        <qaf-support-ws.version>3.0.0</qaf-support-ws.version>
        <selenium.version>3.141.59</selenium.version>
        <test.results.dir>test-results</test.results.dir>
        <run.time>${maven.build.timestamp}</run.time>
        <lib.dir>${project.basedir}/lib</lib.dir>
        <resource.dir>${project.basedir}/resources</resource.dir>
        <output.dir>${test.results.dir}/${run.time}</output.dir>
        <maven.build.timestamp.format>dd_MMM_yyyy_hh_mm_aa</maven.build.timestamp.format>
        <testng.report.title>IQe - Rapid Test Report</testng.report.title>
    </properties>
    <repositories>
        <repository>
            <id>qaf</id>
            <url>https://qmetry.github.io/qaf/dist</url>
        </repository>
        <repository>
            <id>jai</id>
            <url>https://repository.jboss.org/nexus/content/repositories/thirdparty-releases</url>
        </repository>
    </repositories>
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>
        <dependency>
            <groupId>com.qmetry</groupId>
            <artifactId>qaf</artifactId>
            <version>${qaf.version}</version>
        </dependency>
        <dependency>
            <groupId>com.qmetry</groupId>
            <artifactId>qaf-support</artifactId>
            <version>${qaf.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.qmetry</groupId>
                    <artifactId>qaf</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.qmetry</groupId>
            <artifactId>qaf-support-ws</artifactId>
            <version>${qaf-support-ws.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <compilerVersion>${sourceVersion}</compilerVersion>
                    <source>${sourceVersion}</source>
                    <target>${targetVersion}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.8</version>
                <configuration>
                    <source>${sourceVersion}</source>
                    <target>${targetVersion}</target>
                    <showWeaveInfo>true</showWeaveInfo>
                    <complianceLevel>${sourceVersion}</complianceLevel>
                    <aspectLibraries>
                        <aspectLibrary>
                            <groupId>com.qmetry</groupId>
                            <artifactId>qaf</artifactId>
                        </aspectLibrary>
                    </aspectLibraries>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>${testSuiteFile}</suiteXmlFile>
                    </suiteXmlFiles>
                    <reportsDirectory>${test.results.dir}/${run.time}</reportsDirectory>
                    <systemPropertyVariables>
                        <org.uncommons.reportng.xml-dialect>testng</org.uncommons.reportng.xml-dialect>
                        <org.uncommons.reportng.escape-output>false</org.uncommons.reportng.escape-output>
                        <log4j.configuration>file:///${resource.dir}/log4j.properties</log4j.configuration>
                        <outputDir>${output.dir}</outputDir>
                        <test.results.dir>${output.dir}/html</test.results.dir>
                        <json.report.root.dir>${test.results.dir}</json.report.root.dir>
                        <json.report.dir>${output.dir}/json</json.report.dir>
                        <selenium.screenshots.dir>${output.dir}/img</selenium.screenshots.dir>
                        <selenium.screenshots.relative.path>../img</selenium.screenshots.relative.path>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
        </plugins>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.codehaus.mojo</groupId>
                                        <artifactId>aspectj-maven-plugin</artifactId>
                                        <versionRange>[1.0,)</versionRange>
                                        <goals>
                                            <goal>test-compile</goal>
                                            <goal>compile</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <execute />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

看起来 slf4j 实现是从依赖项之一加载的。您可以检查依赖关系树以找出并排除它。或者,您可以添加 log4j slf4j 依赖项并全局排除其他依赖项(例如 logback)。下面是常春藤依赖管理的例子:

<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.7.31"/>

<!-- global exclude -->
<exclude org="ch.qos.logback" />

maven 或 gradle 也可以这样做。

如@user861594 所述,我已将以下依赖项添加到 pom.xml。添加以下依赖项后,“资源”文件夹中的“Log4j.properties”开始工作。

<dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
      <version>2.14.1</version>
      <scope>test</scope>
</dependency>