Logging Overview


I mentioned some uses of logging earlier, so I'll start by summarizing them here. This is sort of the "what" and "why" of logging; I'll provide the "how" right after.

Logging can be used for the following:

  • Audit log This is perhaps the most critical component of logging because it is generally used for record-keeping (auditing) purposes. For example, an organization might require all secure operations to be logged (for example, for compliance with Sarbanes-Oxley and Basel II regulations in the United States).

  • Tracing This involves generating information about what an application is doing at a given point. Tracing is typically sent either to System.out or a file, file being the better practice of the two. Tracing can be used for performance testing, seeing the flow of an application, and more.

  • Error reporting This is a common use for reporting errors and exceptions and is typically sent to System.err, although using System.err for error logging/reporting isn't a good practice. For errors, logging can highly effective for troubleshooting the cause of a given problem.

Logging can also be saved in a file for later consumption, versus something like GUI-based debugging (discussed later in this chapter), which requires manual intervention. Also, at times a GUI debugger isn't even availablefor example, when troubleshooting a problem on a server with faceless applications (that is, ones with no user interface). Also, logging is repeatable because the application can be rerun to generate fresh logging.

Although I've listed several benefits, following are some downsides to logging:

  • Logging statements can clutter code and add extra work to development (that is, adding/removing print statements). Many developers put logging statements in their code but forget to either remove or maintain them, so sometimes the output messages are no longer valid or needed.

  • Logging adds some overhead to the application's execution.

Now that we have reviewed some basics about logging, let's look at how we can implement logging in Java.



Agile Java Development with Spring, Hibernate and Eclipse
Agile Java Development with Spring, Hibernate and Eclipse
ISBN: 0672328968
EAN: 2147483647
Year: 2006
Pages: 219

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net