Both the client and server loggers are implemented as message handlers 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. By default, the log level of the message will be Info.
#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);
Alternatively you can invoke the logger by passing in a rwsf::CallInfo object. By default, a rwsf::CallInfo object is set at the error level. To change the level of a log message, you call the setLogLevel() method. The code below shows this method of using a logger:
rwsf::CallInfo logMessage; logMessage.setLogLevel(rwsf::CallInfo::level); // optional std::string logMessage("Some kind of message.\n"); logMessage.setErrorMessage(logMessage); rwsf::HandlerManager::invokeLogger(logMessage);
Until explicitly set otherwise as outlined in the following sections, the client and server loggers write to the default log file, webservices.log, located in your <installdir>\logs directory.
There are two ways to use logging in the client:
by configuring it in the client-handlers.xml file
by creating a logger explicitly in your implementation
The client logger is configured in the file client-handlers.xml:
<configuration> <logger name="RWSFClientLogger"> <property name="filename" value="client.log"/> <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. 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. Until this is done, log messages are written to the default log file, webservices.log, described in Section 12.3, "Using the Logger."
rwsf::HandlerManager::loadConfiguration("client-handlers.xml");
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)
The above lines code are all generated automatically in the HydraExpress sample clients. With them in place, logging can be performed as described in Section 12.3.
You can also do client-side logging without using the configuration file. The advantage of using the configuration file is that you can change the logging level and the output file name at runtime, without having to recompile your code. But, if you prefer, you can simply create a logger and explicitly set it on the HandlerManager.
rwsf::DefaultLogger *logger = new rwsf::DefaultLogger; logger->setLogLevel(rwsf::CallInfo::Info); logger->setFileName("client.log"); rwsf::HandlerManager::setLogger(logger);
Using this method, none of the elements described in Section 12.3.2 are required, only the above code. As with the previous setup, logging itself is performed as described in 10.Section 12.3.
© Copyright Rogue Wave Software, Inc. All Rights Reserved. All Rights Reserved. Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. HydraExpress is a trademark of Rogue Wave Software, Inc. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.