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>
Advertisement
Answer
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>