alessandro
16 years agoNew Contributor
a way to change log file at runtime
hallo,
in my project (with soapui 2.5) I needed to have in a certain directory a different log file for each test case run, instead of always writing to soapui.log file (set in the soapui-log4j.xml).
since I wasn't able to find a way to do it in the forum, I'd like to share it here:
1) I wrote a listener (a java class) for the test case (as described in the documentation)
2) in the method beforeRun I put these lines:
RollingFileAppender rfa = (RollingFileAppender) Logger.getRootLogger().getAppender("FILE");
rfa.setFile(yourdir + yournewlogfile);
rfa.activateOptions();
yourdir is a directory set a runtime (you can write it as a TestSuite property and read it from the listener)
yournewlogfile is set at runtime in a similar way
3) I put in the method afterRun these lines:
RollingFileAppender rfa = (RollingFileAppender) Logger.getRootLogger().getAppender("FILE"); rfa.setFile("soapui.log");
rfa.activateOptions();
***********************
hope this could be of help to someone
alessandro
bytheway: I was (and I am still ) new to log4j, so if there is anyone with good hints please share!
in my project (with soapui 2.5) I needed to have in a certain directory a different log file for each test case run, instead of always writing to soapui.log file (set in the soapui-log4j.xml).
since I wasn't able to find a way to do it in the forum, I'd like to share it here:
1) I wrote a listener (a java class) for the test case (as described in the documentation)
2) in the method beforeRun I put these lines:
RollingFileAppender rfa = (RollingFileAppender) Logger.getRootLogger().getAppender("FILE");
rfa.setFile(yourdir + yournewlogfile);
rfa.activateOptions();
yourdir is a directory set a runtime (you can write it as a TestSuite property and read it from the listener)
yournewlogfile is set at runtime in a similar way
3) I put in the method afterRun these lines:
RollingFileAppender rfa = (RollingFileAppender) Logger.getRootLogger().getAppender("FILE"); rfa.setFile("soapui.log");
rfa.activateOptions();
***********************
hope this could be of help to someone
alessandro
bytheway: I was (and I am still ) new to log4j, so if there is anyone with good hints please share!