Skip to content

Instantly share code, notes, and snippets.

@renaudfv
Last active October 6, 2022 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renaudfv/25676b81049c6df22903c7e9e28f6fd5 to your computer and use it in GitHub Desktop.
Save renaudfv/25676b81049c6df22903c7e9e28f6fd5 to your computer and use it in GitHub Desktop.
Simple Processing logging setup
import java.io.PrintStream;
import java.io.FileOutputStream;
import java.sql.Timestamp;
void setup() {
try{
PrintStream outStream = new PrintStream(new FileOutputStream(dataPath("out.log")));
PrintStream errStream = new PrintStream(new FileOutputStream(dataPath("err.log")));
System.setOut(outStream);
System.setErr(errStream);
}catch(Exception e){
println(e);
}
}
void draw() {
try {
if(frameCount > 100)
throw new Exception("This is unfortunate");
else
println(ts() + ": sample message at frame " + frameCount);
} catch(Exception e) {
System.err.println(e);
exit();
}
}
Timestamp ts() {
return new Timestamp(System.currentTimeMillis());
}
void exit() {
println(ts() + " Successfull exit");
super.exit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment