next up previous contents
Next: The Interface Services Up: Other Base Services Previous: Other Base Services

The HsDebug, HsMessage, and HsError Services

As the HaystackRootServer allows for a multitude of services to run concurrently, it was necessary for us to create a mechanism by which we could log errors and messages in an intelligent fashiongif. This would prevent the user from being barraged with a variety of status and error messages that might be a normal part of the system's function. The three services, HsDebug, HsMessage, and HsError provide this functionality through a very clean interface.

All three of these services extend the LoggerService (in the haystack.service.misc package). This service provides the basic functionality which allows messages to be printed to any arbitrary location (i.e. file, screen, etc.). Every time the print() command is invoked on any of the three services above, the LoggerService pretty prints the message to the appropriate location. Both HsMessage and HsError are trivial extensions to this. HsDebug, on the other hand, provides a slightly more complex set of functions.

The customary way to debug an application has usually consisted of setting some boolean value (call it debug). When you want to debug your application you set the value to true. Inside your code, the programmer ordinarily places conditionals: if (debug) then print out some stuff to STDERR or STDOUT. HsDebug provides a much more refined logging mechanism. A user can set debugging on for anything as fine grained as a class. Within a class, the class developer can call the function print() on the HsDebug service. The arguments to print() are the reference to the object being debugged (i.e. the this in Java), and the message to print. Someone who is debugging the system can tell HsDebug, by means of the debugClass() method which classes they are interested in debugging (to turn this off you would use the method unDebugClass() with the class name as an argument).

Now, whenever print() is invoked, the HsDebug service checks to see if debugging is turned on for the invoking class. If it is, the debugging message is printed. HsDebug also allows the programmer to set where the debug messages are printed to. The method toScreen() resets messages to System.err (i.e. STDERR).


next up previous contents
Next: The Interface Services Up: Other Base Services Previous: Other Base Services

Copyright 1998, Eytan Adar (eytan@alum.mit.edu)