无法生成 .log 文件,但有输出控制台

Failed to generate .log file, but output console is there

我已尝试在 Serenity Cucumber 框架中实现日志,它会在控制台中打印日志,但不会生成 .log 文件

这是 logback-test.xmlsrc/test/resources

<configuration>
    <appender name="STDOUT"
        class="ch.qos.logback.core.ConsoleAppender">
        <File name="File" fileName="admin.log">
            <encoder>
                <pattern> %d{HH:mm:ss.SSS}
                    [%thread] %-5level %logger{36} - %msg ..................%n </pattern>
            </encoder>
        </File>
    </appender>
    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>admin.log</file>
        <encoder>
            <pattern>
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg
                ..................%n
            </pattern>
        </encoder>
    </appender>
    <logger name="root" level="DEBUG" />
    <logger name="net.serenitybdd" level="INFO" />
    <logger name="net.thucydides" level="INFO" />
    <root level="INFO">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>


pom.xml

中添加了以下依赖项
<dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.0.13</version>
        </dependency>

A ConsoleAppender 不会写入文件,只会忽略其下的 file 配置元素。相反,您应该使用 FileAppender:

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg..................%n
            </pattern>
        </encoder>
    </appender>
    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>admin.log</file>
        <encoder>
            <pattern>
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg..................%n
            </pattern>
        </encoder>
    </appender>
    <logger name="root" level="DEBUG" />
    <logger name="net.serenitybdd" level="INFO" />
    <logger name="net.thucydides" level="INFO" />
    <root level="INFO">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="FILE" />
    </root>
</configuration>