Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging in Serenity HTML Dashboard reports. #213

Open
pushprajsingh05 opened this issue Oct 29, 2018 · 12 comments
Open

Logging in Serenity HTML Dashboard reports. #213

pushprajsingh05 opened this issue Oct 29, 2018 · 12 comments

Comments

@pushprajsingh05
Copy link

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?

@wakaleo
Copy link
Member

wakaleo commented Oct 29, 2018

Serenity uses SLF4J, so this would be the most natural approach.

@pushprajsingh05
Copy link
Author

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?

@wakaleo
Copy link
Member

wakaleo commented Oct 29, 2018

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).

@jeevan1987cool
Copy link

jeevan1987cool commented Sep 24, 2020

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>

@b-sagar
Copy link

b-sagar commented Sep 21, 2021

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

@wakaleo
Copy link
Member

wakaleo commented Sep 21, 2021

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

@b-sagar
Copy link

b-sagar commented Sep 21, 2021

Thank you @wakaleo ..
Will explore if there is any setting available in slf4j or Maven

@sudeesimsek
Copy link

@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);
}

@sudeesimsek
Copy link

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?

@wakaleo
Copy link
Member

wakaleo commented Dec 23, 2021

What error are you getting? What makes you think this is related to Serenity?

@wakaleo
Copy link
Member

wakaleo commented Dec 24, 2021

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.

@gauravkhuraana
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants