Logging in Service Code
The easiest and best method for logging events in service code is to use the global Agent logger, rather than the Web services logger. The global Agent logger is best suited for services, handlers, connectors, and transports. This global log file, located at <installdir>/logs/agent.log, is instantiated automatically when the Agent is started.
Using the Global Agent Logger in Service Code
This section introduces how to use the global Agent logger. For a complete discussion, see Chapter 6, “Logging,” in the HydraExpress User Guide.
At Agent start-up, the Agent instantiates a global Agent logger, using it to record significant events related to general Agent processes and service execution. You have access to this logger in HydraExpress server-side code. You can also create your own loggers if you want to log information to locations other than the default log output file.
You can log information from any custom service that you write. In many cases, logging will be functionality added to a service with some other main purpose, but you might also create a service just to log some information.
The default Agent logger is defined in the file <installdir>\conf\loggers.xml.
From within a HydraExpress service, you can access the default Agent logger from the
rwsf::LogManager singleton. For example, this code gets the default Agent logger and logs a message:
#include <rwsf/core/LogManager.h>
#include <rwsf/core/Logger.h>
rwsf::Logger logger = rwsf::LogManager.getLogger();
logger.info("My log message.");
NOTE >> The Agent logger cannot be used by the client or standalone services. Instead, use the Web services logger,
“Logging in Client Code” .
Server-side Logging through the Web Services Logger
Although service code should use the global Agent logger (
“Using the Global Agent Logger in Service Code” ), be aware that the Agent automatically logs some Fatal and Error messages to the Web services logger which may be useful for debugging. This file is located in your
<installdir>\logs directory.