Additional Notes on Logging


  • The logging facility allows you to attach arbitrary filters to a logger or handler. The Filter interface defines one methodisLoggablewhich takes a LogRecord as a parameter. Using information in the LogRecord, the job of isLoggable is to return true if the message should be logged or false otherwise. You might code a Filter implementation that ignores log messages over a certain length, for example.

  • The logging facility provides support for internationalization. See the Java API documentation for more information and Additional Lesson III for a brief discussion of internationalization in general.

  • You may need to change logging properties while the application is already executing. Once you have changed the physical properties file, you can use the LogManager class method readConfiguration to reload the properties file. In order to do so, you will need to represent the properties file as an InputStream. See Lesson 11 for information on how to read files using input streams.

  • You learned to modify the logging.properties to define logging characteristics at runtime. You can supply a custom configuration file instead of using the logging.properties file. To do so, set the value of the system property java.util.logging.config.file. One way to do this is on the command line when you start the Java application. For example:

     java -Djava.util.logging.config.file=sis.properties sis.MainApp 

  • The Logger class provides convenience methods for logging special situations. You can use entering and existing to simplify logging entry to a method and exits from it. You can use the throwing method to simplify logging an exception. Refer to the Java API documentation for Logger for more information.



Agile Java. Crafting Code with Test-Driven Development
Agile Javaв„ў: Crafting Code with Test-Driven Development
ISBN: 0131482394
EAN: 2147483647
Year: 2003
Pages: 391
Authors: Jeff Langr

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