I would like to know if there are any performance benefits in using a logger (like log4j) and using a System.out.println to print debug / info in an application server. I understand that the use of a logging mechanism is better, but has anybody seen a significant difference between them ?
I gonna say 3 benefits for now.:
* You can save the log in a file.
* You can define the level of log. Like, info, debug... This help you like, just showing when the problem is an error.
* You can send the output to more than one exit sysout.
i think sysout will be faster than logging in DEBUG level. but when your application goes to production, you will not log everything. if you do so you have to face a big performance issue. logger gives you much convenient ways implement logging.
There is no necessary significant performance penalty of using a logger instead of System.out.println(). The time taken to actually print a statement on console far exceeds any overhead of the actual call.
That does not mean log statements should be used blindly - there can be significant performance problems when using logging (special when writing to a file, with log4j - its synchronized.)
However if the choice is between using Println() and logger then logger give significant benefits with no compromise to performance!