Writing console output to a text file

The output in my sketch produces a maximum of 500 lines, which forces the first lines to disappear. My output is thousands of lines. I need code that will write all output lines from the console window to a text file. Thank you in advance

1 Like

You can log directly to a file with createWriter()

https://processing.org/reference/createWriter_.html

or append your log lines to a StringList and then save it to a file with saveStrings().

https://processing.org/reference/StringList.html
https://processing.org/reference/saveStrings_.html

like this:

StringList log = new StringList();
void draw(){
  log.append(str(frameCount));
  if(frameCount==60) {
    saveStrings("log.txt", log.array());
    exit();
  }
}

There are many other options for structured data – for example, logging to a Table object and then saving to csv https://processing.org/reference/Table.html – or logging to JSON, or XML et cetera. But for plain text line logs, createWriter() or saveStrings() should solve your problem.

1 Like

Jeremy, Thanks for your expeditious response. I will try your suggestions that I believe will solve my issue. Best Regards.

1 Like