英文:
Failed to generate .log file, but output console is there
问题
我已经在Serenity Cucumber框架中尝试实现日志记录,并且它在控制台中打印日志,但是没有生成.log文件。
这是位于src/test/resources
目录下的logback-test.xml
文件:
<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>
英文:
I have tried to implement logs in the Serenity Cucumber framework and it prints logs in the console but doesn't generate a .log file.
This is logback-test.xml
under src/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>
Added below dependency in pom.xml
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
答案1
得分: 1
<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>
英文:
A ConsoleAppender
won't write to a file, and will just ignore the file
configuration element under it. Instead, you should use a 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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论