Configuring and Using a Client Logger
HydraExpress sample clients all feature loggers that are configured in the way described in this section.
The client logger is configured in the file client-handlers.xml located by default in the project’s generated conf directory:
 
<configuration>
<logger name="RWSFClientLogger">
<property name="filename" value="client.log"/> <!-- if not defined, writes to stdout -->
<property name="level" value="Info"/>
</logger>
<!-- service definitions, if any -->
</configuration>
The output from this logger is written to the file client.log in the directory where the client is invoked. If the filename property is omitted, log messages are written to stdout.
Note that the level is set at Info, which means all messages are reported.
At startup, the line of code below loads the configuration file and rwsf::HandlerManager is initialized with the logger.
 
rwsf::HandlerManager::loadConfiguration("../conf/client-handlers.xml");
NOTE: Note that if the logger is invoked in your code before the handlers configuration file is loaded, no logging occurs.
Finally, for loadConfiguration() to be successful, a static message handler with the logger name from the configuration file must be defined. You accomplish this by placing the macro shown below in the client implementation file at file scope. Note the use of the provided DefaultLogger class to carry out the actual logging.
 
using rwsf::DefaultLogger;
RWSF_DEFINE_STATIC_MESSAGE_HANDLER("RWSFClientLogger", DefaultLogger)
Now let’s put it all together. Here is an excerpt from client code that invokes a logger:
 
#include <rwsf/webservice/HandlerManager.h> //1
...
using rwsf::DefaultLogger; //2
RWSF_DEFINE_STATIC_MESSAGE_HANDLER("RWSFClientLogger", DefaultLogger)
...
rwsf::HandlerManager::loadConfiguration("../../conf/client-handlers.xml"); //3
rwsf::HandlerManager::invokeLogger("This is a warning message", //4
rwsf::CallInfo::Warning);
//1 Required include
//2 Define the static message handler for logging
//3 Load the logger configuration file
//4 Invoke the logger, in this case setting it to the non-default Warning level. Note that the generated code does not include this line, although it includes the previous three.