Writing effective log messages

A log system is a mechanism that allows you to write information to one or more destinations. A Logger has the following components:

  • One or more handlers: A handler will determine the destination and format of the log messages. You can write log messages in the console, a file, or a database.
  • A name: Usually, the name of a Logger used in a class is based on the class name and its package name.
  • A level: Log messages have different levels that indicate their importance. A Logger also has a level to decide what messages it is going to write. It only writes messages that are as important as, or more important, than its level.

You should use the log system because of the following two main reasons:

  • Write as much information as you can when an exception is caught. This will help you localize the error and resolve it.
  • Write information about the classes and methods that the program is executing.

In this recipe, you will learn how to use the classes provided by the java.util.logging package to add a log system to your concurrent application.

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

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