Performance

The second reason to use a logging framework is performance. Although it is not good to optimize for performance before we profile the code (premature optimization), using some methodology known to be slow and inserting several lines into our performance-critical code, invoking slow methods is not really professional either. Using a well-established, highly optimized framework in a way that is industry best practice should not be questionable.

Using System.out.println sends the message to a stream and returns only when the IO operation is done. Using real logging handles the information to the logger and lets the logger do the logging asynchronously, and it does not wait for completion. It is really a drawback that log information may be lost if there is some system failure, but this is usually not a serious issue considering how rarely that happens and what is on the other side of the wage: performance. What do we lose if there is a missing debug log line when the disk got full, anyway rendering the system unusable?

There is one exception to this: audit logging—when some log information about the transactions of the system has to be saved for legal reasons so that the operation and the actual transactions can be audited. In such a case, the log information is saved in a transactional manner, making the log part of the transaction. Because that is a totally different type of requirement, audit logging is not usually done with any of these frameworks.

Also, System.out.println is not synchronized and that way different threads may just garble the output. Log frameworks pay attention to this issue.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.41.235