# Writing console output to a text file

**URL:** <https://discourse.processing.org/t/writing-console-output-to-a-text-file/16949>\
**Category:** Coding Questions\
**Created:** [January 8, 2020, 6:59am UTC](https://discourse.processing.org/t/writing-console-output-to-a-text-file/16949 "2020-01-08T06:59:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![idisc007](https://avatars.discourse-cdn.com/v4/letter/i/b5a626/32.png) [@idisc007](https://discourse.processing.org/u/idisc007)\
**Post date:** [January 8, 2020, 6:59am UTC](https://discourse.processing.org/t/writing-console-output-to-a-text-file/16949/1 "2020-01-08T06:59:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [January 8, 2020, 7:54am UTC](https://discourse.processing.org/t/writing-console-output-to-a-text-file/16949/2 "2020-01-08T07:54:02Z")

</div>

You can log directly to a file with `createWriter()`

[https://processing.org/reference/createWriter\_.html](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/StringList.html)  
[https://processing.org/reference/saveStrings\_.html](https://processing.org/reference/saveStrings_.html)

like this:

```auto
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](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.

---

<div class="post-metadata">

**Author:** ![idisc007](https://avatars.discourse-cdn.com/v4/letter/i/b5a626/32.png) [@idisc007](https://discourse.processing.org/u/idisc007)\
**Post date:** [January 8, 2020, 8:05am UTC](https://discourse.processing.org/t/writing-console-output-to-a-text-file/16949/3 "2020-01-08T08:05:31Z")

</div>

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