1

Thanks for your time,

Task: I am running a lot of parallel tests using cucumberJVM / Maven Surefire (forkCount), upwards of around 15+ tests at the same time on my GRID setup. Is it possible for me to have an individual log file per Junit @Test (with the test method as the log name) and each cucumberJVM Scenario to have a log for itself?

I'm not sure if this is even viable but its something I am trying to achieve, I have basic logging so far that writes everything to one .log file, I am doing a lot of reading on log4j2 at the moment but the website is overwhelming so far.

my current log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <File name="file" fileName="app.log">
      <PatternLayout>
        <Pattern>%d %p %c{1.} [%t] %m %ex%n</Pattern>
      </PatternLayout>
    </File>
    <Console name="STDOUT" target="SYSTEM_OUT">
      <PatternLayout pattern="%m%n"/>
    </Console>
  </Appenders>
  <Loggers>
    <Root level="trace">
      <AppenderRef ref="file" level="DEBUG"/>
      <AppenderRef ref="STDOUT" level="INFO"/>
    </Root>
  </Loggers>
</Configuration> 

I am still investigating different types of appenders, is there any I should consider using for this task in particular? I have a simple LoggerFactory which I am using to write to the Log

package supportFactory;



import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;


public class LoggingFactory {


    public static Logger Log = LogManager.getLogger();                                   


    public void debug(String message) {
        Log.debug("DEBUG: " + message); 
    }

    public void info(String message) {
        Log.debug("INFO: " + message);
    }

    public void warn(String message) {
        Log.debug("WARNING: " + message);
    }

    public void error(String message) {
        Log.debug("ERROR: " + message);
    }

    public void fatal(String message) {
        Log.debug("FATAL: " + message);

    }

}

I am able to get the running scenario with the following in my @Before (hook):

    TestRunner.scenario = scenario;
    System.out.println("Scenario: " + scenario.getId());

This returns Feature AND scenario name, just this with a .log on the end would be brilliant per test run

Any guidance is massively appreciated here.

symon
  • 670
  • 1
  • 7
  • 20
  • You could try a setup like the one I suggested as an [answer for another question](https://stackoverflow.com/a/43404124/3284624). – D.B. Sep 08 '17 at 04:34

0 Answers0