Last active
October 6, 2022 15:16
-
-
Save renaudfv/25676b81049c6df22903c7e9e28f6fd5 to your computer and use it in GitHub Desktop.
Simple Processing logging setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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