The Web Services Logger for Client Applications
The Web services logger is available to client-side applications.
NOTE: While it is possible to use the Web services logger in services, it is not recommended. Rather, use the Agent logger, discussed in
The Agent Logger. Logging is implemented in the generated sample application by default. The default client logging level is Info, resulting in all messages reported.
The defined log levels are:
Table 12 – Default Logging Levels for the Web Services Logger
Level | Description | Default |
---|
NONE | No logging | |
FATAL | Fatal messages only | |
ERROR | Error and Fatal | |
WARN | Warn, Error, and Fatal | |
INFO | Info, Warn, Error, and Fatal | Client default level |
For logging set to some level, messages at or above that level are reported. For example, for a level of Error, messages defined as Error or Fatal are reported. To have all messages reported, set the level to Info, which is the default in the generated client code.
The logger is implemented as a message handler and invoked statically via the
rwsf::HandlerManager class. The simplest way to log a message is to invoke the logger with a string and an optional log level describing the severity of the message:
#include <rwsf/webservice/HandlerManager.h> // required include
rwsf::HandlerManager::invokeLogger("This is an info message");
rwsf::HandlerManager::invokeLogger("This is a warning message",
rwsf::CallInfo::Warning);
In client code, the invokeLogger() method uses the logger defined in the client-handlers.xml file. If no logger configuration is found, then logging defaults to the default log file, webservice.log.
You can log events in your client in one of two ways:
Configure a logger in the generated configuration file
client-handlers.xml file. This method allows you to change the logging level and the output file name at runtime, without having to recompile your code.
Create a logger explicitly in your implementation.
By default, the code generator uses the first method, creating a logger handler and placing its configuration in the generated conf/client-handlers.xml file. The client code then loads the configuration using the loadConfiguration() method:
rwsf::HandlerManager::loadConfiguration("client-handlers.xml");
If you undefine the logger by commenting out the above line in the generated client implementation or removing the logger element in the client-handlers.xml, then only Error and Fatal messages are logged to the webservice.log file.
For more information on the Web services logger and client logging, please see
“Web Service Logging,” in the
HydraExpress Web Service Development Guide.