I'm writing a program in Java that simulates gravity, and in it I have a bunch of log statements (to System.out). My program is running really slowly, and I think the logging might be part of the reason. Is there any way to disable System.out, so that my program doesn't slow down when printing, or do I have to manually go through and comment/uncomment each one to enable/disable debug statements?
There is a setOut( PrintStream ) method in java. lang. System - if the security manager will let you, you can redirect System. out to any PrintStream - you could write to a file or make a custom PrintStream to hold the last N outputs, or just make a bit-bucket that discards all output.
You can use System. setOut() to redirect the System. out.
Java System. out. println() is used to print an argument that is passed to it.
Again an output stream gobbler could work, something perhaps like...
System.setOut(new PrintStream(new OutputStream() {
@Override
public void write(int arg0) throws IOException {
}
}));
But a better solution is to use a formal logging utility as has already been mentioned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With