Could you explain what you’re trying to achieve?
Is this for debugging purpose? Do you want to have one file per user, or only one file for all?
In the latter case, the easiest way if to have a slf4j logger into your simulation, and a dedicated appender configured in logback.xml. Do you need them for that?
Yes, it’s for debugging purposes. The information I’m pulling from our site is too big to be printed to the console (I can’t see all the information it returns).
It would just be 1 file for all. Right now I’m only testing with one user so I can get the structure of my test working. Once I get it working, I’ll scale up the users and take out the debugging info.
If you want to write your results to a file, you can use java.io classes.
1/ outside the scenario definition, create a new writer :
val writer = {
val fos = new java.io.FileOutputStream(“filename”)
new java.io.PrintWriter(fos,true)
}
You’ll have to set autoFlush to true, since you can’t properly close the PrintWriter and ensure content will be flushed to file. (and you can use import instead of fully qualified classes, of course )
2/ simply replace println(s.getAttribute(“Tasks”)) by writer.println(s.getAttribute(“Tasks”))
I forgot to say that this solution is only fit for your use case : scenario building, 1 user, where performance does not matter too much.If you want to log some information to a file after you built your scenario and you started scaling up the users, Stephane’s solution is much better, as it won’t slow down your simulation as much as mine.
I might be wrong, but I’d tend to say that FileOutputStream is not threadsafe and you might run into issues, even with one user.
That’s the reason why I proposed an slf4j based solution that would handle concurrency for you.
val logger = org.slf4j.LoggerFactory.getLogger(“myDebugLogger”)
.exec((s: Session) => {
logger.debug(s.getAttribute(“Tasks”))
s
})
Then configure a FileAppender as described in Logback documentation: