I\'m working into a method trying to change the default rest-assured log (which goes to the console) to a file using log4j.
It\'s a JUnit project which methods final
One possible modification to Heri's answer - instead of StringBuilder one can use ByteArrayOutputStream - that helps if one deals with multi-language data, e.g.
// [...]
PrintStream getPrintStream() {
if (printStream == null) {
OutputStream output = new OutputStream() {
ByteArrayOutputStream baos = new ByteArrayOutputStream()
@Override
public void write(int b) throws IOException {
baos.write(b)
}
@Override
public void flush() {
logger.debug(this.baos.toString())
baos = new ByteArrayOutputStream()
}
}
printStream = new PrintStream(output, true) // true: autoflush must be set!
}
return printStream
}
// [...]