Open pushprajsingh05 opened 5 years ago
Serenity uses SLF4J, so this would be the most natural approach.
Beauty of Serenity is almost all of the things are ready to use, no configuration require at all. I didnt make any configuration so far.
How about logging? Is it available OOTB or I need to set it up?
Which API , function I would use? Any doc to refer?
Serenity uses SLF4J (https://www.slf4j.org). Any messages logged using an SLF4J logger will appear in the console, as long as you have a correct SLF4J implementation on your path, e.g.
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
Then you can use an SLF4J logger like this:
private static final Logger LOGGER = LoggerFactory.getLogger(StepDefinitions.class);
@Given("^a customer who is domiciled in (.*)")
public void a_customer_who_is_domiciled_in(String country) {
LOGGER.info("Customer domiciled in {}", country);
}
The starter projects have a configured logbook-test.xml (see https://github.com/serenity-bdd/serenity-cucumber-starter for am example).
Hey @wakaleo I have tried to implement it and it prints logs in the console but doesn't generate a .log file. I guess it is because of below error
17:25:22,184 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
17:25:22,184 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback-test.xml] at [file:/Users/ID05001/eclipse-workspace/demo-aem-automation/target/test-classes/logback-test.xml]
17:25:22,298 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
17:25:22,443 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
17:25:22,451 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
17:25:22,467 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:42 - no applicable action for [File], current ElementPath is [[configuration][appender][File]]
17:25:22,468 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
17:25:22,511 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [root] to DEBUG
17:25:22,511 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [net.serenitybdd] to INFO
17:25:22,511 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [net.thucydides] to INFO
17:25:22,511 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
17:25:22,511 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
17:25:22,512 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
17:25:22,513 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@5bb21b69 - Registering current configuration as safe fallback point
17:25:22.517 [main] INFO c.demo.aem.automation.pages.BasePage - ------------- Hello World ----------------
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>
<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>
This is log4j.properties
under src/test/resources
log4j.rootLogger=DEBUG, STDOUT, file
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
log4j.appender.STDOUT.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=./target/logs/demo-aem-automation.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{dd-MM-yyyy HH:mm:ss} %-5p %c{1}:%L - %m%n
Added below dependency in pom.xml
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
</dependency>
Serenity uses SLF4J (https://www.slf4j.org). Any messages logged using an SLF4J logger will appear in the console, as long as you have a correct SLF4J implementation on your path, e.g.
<dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.0.13</version> </dependency>
Then you can use an SLF4J logger like this:
private static final Logger LOGGER = LoggerFactory.getLogger(StepDefinitions.class); @Given("^a customer who is domiciled in (.*)") public void a_customer_who_is_domiciled_in(String country) { LOGGER.info("Customer domiciled in {}", country); }
The starter projects have a configured logbook-test.xml (see https://github.com/serenity-bdd/serenity-cucumber-starter for am example).
Hi @wakaleo , I would like to enable real time console logging for my Serenity project. The project mainly verifies backend systems like AWS components, REST endpoints. The current logging of Serenity logs all the output to console after the test/s is/are finished. Meanwhile, there is no way to know the progress of execution. If there is any setting to enable real time console logging, it will help greatly to know how much execution is done and current progress of execution. Thank you
What makes you think logging happens after execution is completed? Serenity logs to the console in real time - the rest is up to the slf4j/maven/gradle config
Thank you @wakaleo .. Will explore if there is any setting available in slf4j or Maven
@When("I search with {string} in the home page") public void iSearchWithInTheHomePage(String term) { term = "kaan"; actor.attemptsTo(LookForProductItem.about(term)); try { Thread.sleep(30000); } catch (InterruptedException e) { e.printStackTrace(); } LOGGER.info("browser and main page are opened {}", term); }
I implement all the steps you told but it does not accept the term variable inside the log brackets and gives an error. What could be the reason?
What error are you getting? What makes you think this is related to Serenity?
If you are getting an error from the logger, you will need to check the documentation or raise an issue with the logging library you are using.
How can i put the logging into a file.. to not see things which are logged by other processes when the program is run. but just those statements which i have printed using log.info
Looking for logging mechanism.
One for debugging purpose and and for info purpose. So that I can switch on/off when I want to see info logs and when I want to see debug logs.
log.info("__"); log.debug("__");
when debugging mode is on, both will appear and when info mode is on only info logs would appear.
Is this present Out Of the Box in serenity?