Our MathImpl class is now ready to generate logs. But, where do all those log messages end up? Well, we can either write them to the console output of the Grid Services container, or write them in a file. This is specified in a file you'll find at the root of your GT3 installation: $GLOBUS_LOCATION/ogsilogging.properties. Just add the following line at the end of that file:
org.globus.progtutorial.services.core.logging.impl.MathImpl=console,info
Each line of that file specifies how logging must be handled in those classes that are logging-enabled. In our case, the class where we've enabled logging is org.globus.progtutorial.services.core.providers.impl.MathImpl. The two options after the equals sign (=) tell the logger where it should write the messages, and how to filter them (according to their level).
The messages can either be written to the console, by specifying the console option, or to a file, by writing the file name. This file will be created in the directory specified in another file called $GLOBUS_LOCATION/ogsilogging_parms.properties (in the option logDestinationBasePath).
The filtering option can take any of the following values:
all or debug
trace
info
warn
error
fatal
off
Each of these correspond to the logging levels we saw earlier. We can also ask for all or none of the messages to be displayed. Take into account that you can only specify one level of filtering. For example, if you select the warn level, you will get all the messages generated at that level and at 'more severe' levels (error and fatal). The logic behind this is that usually you don't want the log message from one specific level, but all the messages which have at least a certain severity (if you're interested in the warnings, you're probably also interested in the errors and the fatal exceptions).
Let's put all this to the test. Since we haven't changed the interface of the service we can, once again, reuse the MathService client we've used in previous examples.
java \ -classpath ./build/classes/:$CLASSPATH \ org.globus.progtutorial.clients.MathService.Client \ http://127.0.0.1:8080/ogsa/services/progtutorial/core/logging/MathService \ 5
Since we've set the log level to info, we should get both Info and Warn messages. You should see this in the console output of the services container:
[DATE TIME ] CLASS_NAME [add:39] INFO: Addition invoked with parameter a=5 [DATE TIME ] CLASS_NAME [getValue:55] INFO: getValue() invoked
Each log entry includes the date and time of the entry, plus the name of the class which produced the log entry (in our case org.globus.progtutorial.services.core.providers.impl.MathImpl) We didn't get any Warn message because we need to invoke the add method with the value zero. Let's try to do that:
java \ -classpath ./build/classes/:$CLASSPATH \ org.globus.progtutorial.clients.MathService.Client \ http://127.0.0.1:8080/ogsa/services/progtutorial/core/logging/MathService \ 0
You should see this in the console:
[DATE TIME ] CLASS_NAME [add:39] INFO: Addition invoked with parameter a=0 [DATE TIME ] CLASS_NAME [add:41] WARN: Adding zero doesn't modify the internal value! [DATE TIME ] CLASS_NAME [getValue:55] INFO: getValue() invoked
Finally, let's try changing the log level in the $GLOBUS_LOCATION/ogsilogging.properties file:
org.globus.progtutorial.services.core.logging.impl.MathImpl=console,
warn
You will need to restart the container for this change to have effect. Once you've done so, try running the client again (passing a zero as the value to add). You should see this in the console:
[DATE TIME ] CLASS_NAME [add:41] WARN: Adding zero doesn't modify the internal value!
Since the log level is Warn, this means that the logger will only output messages which are 'at least as severe as a warning'. Since an Info message is not as severe as a Warn message, it will not pass the filter.