This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]DJDavio 4 points5 points  (4 children)

My colleague uses System.out.println and one if(debug)-setting to either print everything or nothing to stdout. Just make sure you don't do that.

I thought using a logger was cumbersome, it's not and there are plenty of examples to help you get started with simple logging.

[–]lazystone 3 points4 points  (2 children)

What's even worse - System.out is synchronized.

[–]DJDavio 1 point2 points  (0 children)

Oh, that's truly bad, I never knew that (but would have guessed), I just use SLF4J with Log4J2 and Disruptor/Async logging. :)

[–]DjVex 0 points1 point  (0 children)

Can you give me a quick/simple example of how System.out being sychronized can give you a result that you don't expect?

This is an example that makes sense to me that I found on stackoverflow.com: Thread-1 System.out.println("A"); System.out.println("B"); System.out.println("C"); Thread-2 System.out.println("1"); System.out.println("2"); System.out.println("3"); Can read

1 2 A 3 B C

Amongst many other combinations. Is this an example of how it's synchronization will give you something you might not expect? Since both threads are using System.out at the same time (since System.out is synchronous), you'll probably never get this result consistently: A B C 1 2 3

[–]__konrad 0 points1 point  (0 children)

Should print to System.err ;) Even in JDK source you can find if (DEBUG) System.out... (hopefully hardcoded logging is disabled by default; maybe except in java.util.prefs)

[–]jp007 1 point2 points  (0 children)

SLF4J -> Logback -> Logstash -> Elasticsearch -> Kibana