HydraExpress™ C++ API Reference Guide

Product Documentation:
   HydraExpress C++
Documentation Home
List of all members | Public Member Functions | Static Public Member Functions
rwsf::LogManager Class Reference

Provides a central point for accessing logger instances. More...

#include <rwsf/core/LogManager.h>

Public Member Functions

 LogManager ()
 ~LogManager ()

Static Public Member Functions

static bool addLogger (const Logger &logger)
static void destroy ()
static Logger getLogger ()
static Logger getLogger (const std::string &name)
static void init ()
static void load (const std::string &file)
static void removeLogger (const std::string &name)
static void setDefault (const std::string &name)

Detailed Description

rwsf::LogManager is a singleton providing a central point for accessing logger instances. Loggers can be registered with the rwsf::LogManager class, and can then be accessed from anywhere in the code.

The LogManager class registers global Agent loggers, i.e., those used for service implementations, handlers, transports, and connectors. For clients and standalone servers, instead use the Web services logger. See the logging chapter in the Web Service Development Guide for more information.

Loggers are typically loaded on system start by parsing the logger configuration file (typically <installdir>\conf\loggers.xml). This file defines a set of rwsf::Logger instances that are tied to specific logging implementations (such as LogFileWriter or LogLevelFilter). These defined rwsf::Logger instances are then added to the global LogManager and made available by name (or by default specification) through getLogger().

The following example demonstrates how to define two loggers, log1 and log2, in the loggers.xml file, then access those loggers from the code.

In loggers.xml:

<logger name="log1" class="rwsf_core.createLogLevelFilter">
<property name="logger" value="stdout"/>
<property name="filter" value="info"/>
<logger name="log.file" class="rwsf_core.createFileLogger">
<property name="filename" value="logfile.txt"/>
<property name="formatter" value="rwsf_core.createLogTimeFormatter"/>
<property name="mode" value="overwrite"/>
<logger name="log2" class="rwsf_core.createLogLevelFilter" default="true">
<property name="logger" value="log.file"/>
<property name="filter" value="debug"/>

In C++ code:

The first line gets the log1 logger, which was declared as a stdout logger, filtered on logging level (i.e., only log() calls with logLevel values below the specified filter level get printed, info in this case).

The second line gets the default logger (also defined as the log2 logger). This logger is set up as a standard filter (debug in this case, so dev messages won't get printed to the file) pointing to a file writer named log.file. This log.file logger is set to write to a file called logfile.txt with a standard time format printed on each line. This file overwrites itself the next time the system is started.

Constructor & Destructor Documentation

rwsf::LogManager::LogManager ( )

Default constructor. Creates a guard instance of rwsf::LogManager. This class invokes init() in the constructor, and destroy() in the destructor, allowing for exception-safe handling of the global rwsf::LogManager instance.

rwsf::LogManager::~LogManager ( )


Member Function Documentation

static bool rwsf::LogManager::addLogger ( const Logger logger)

Adds a new logger to the manager. Returns true if the name is not currently in use, otherwise false.

static void rwsf::LogManager::destroy ( )

Destroys the manager. For each call to init(), there must be an associated call to destroy() in order to release the manager.

static Logger rwsf::LogManager::getLogger ( )

Returns the default logger associated with the manager. If the default logger cannot be found, a logger to stderr is returned.

static Logger rwsf::LogManager::getLogger ( const std::string &  name)

Returns a named logger from the manager. If the logger isn't found, this returns an invalid logger (i.e., the Logger::isValid() function returns false).

static void rwsf::LogManager::init ( )

Initializes the manager. For each call to init(), there must be an associated call to destroy() in order to release the manager.

static void rwsf::LogManager::load ( const std::string &  file)

Loads logger instances from a logger configuration file.

FileNotFoundExceptionis thrown if the file referenced by file cannot be found.
static void rwsf::LogManager::removeLogger ( const std::string &  name)

Removes a logger from the manager. This function does not remove the stderr and stdout loggers. If name isn't found in the map of loaded loggers, this function does nothing.

static void rwsf::LogManager::setDefault ( const std::string &  name)

Sets the name of the default logger.

Copyright © 2020 Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave is registered trademark of Rogue Wave Software, Inc. in the United States and other countries, and HydraExpress is a trademark of Rogue Wave Software. All other trademarks are the property of their respective owners.
Provide feedback to Rogue Wave about its documentation.