Search code examples
log4jrobotframeworkacceptance-testing

In Robot framework how to log to console during execution


i'm actually trying to run a keyword from imported test library written in java (RF 3.0.2 , Jython 2.7.1rc3 )

import org.apache.log4j.Logger;

public class Sample
{
private static final Logger logger = Utils.getLogger(Sample.class);

@RobotKeyword("Print Message")
@ArgumentNames({"message"})
public void printMessage(String message)
   {
    logger.info("I'm inside");
   }
}


import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

public class Utils
{
    public static final Logger logger = getLogger(Utils.class);

    public static Logger getLogger(Class<?> clazz)
    Logger logger = Logger.getLogger(className.getClass());
    PropertyConfigurator.configure("/src/main/resources/log4j.properties");
    return logger;
}


log4j.properties :

log4j.rootLogger=DEBUG, Stdout, file
log4j.appender.Stdout=org.apache.log4j.ConsoleAppender
log4j.appender.Stdout.Target=System.out
log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.Stdout.layout.conversionPattern=%d %-5p [%t] %F:%L %m%n
log4j.appender.Stdout.ImmediateFlush=true
log4j.appender.Stdout.follow=true

With this setup i'm able to see log after test execution in robot framework test report but it would be very helpful if i can see logs during test execution as if i was calling log to console keyword.

is There a way to do this ?


Solution

  • You can use listener interface http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#listener-interface to get real time execution information. In docs there is a sample script.

    This is used in RED Robot Editor to get execution status,debug information etc. - source can be found: TestRunnerAgent.py