HydraExpress™ C++ API Reference Guide

 
Loading...
Searching...
No Matches
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.

Note
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>
<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>
<logger name="log2" class="rwsf_core.createLogLevelFilter" default="true">
<property name="logger" value="log.file"/>
<property name="filter" value="debug"/>
</logger>

In C++ code:

static Logger getLogger()
Provides an interface for writing log messages to the logging framework.
Definition Logger.h:58

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

◆ LogManager()

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.

◆ ~LogManager()

rwsf::LogManager::~LogManager ( )

Destructor.

Member Function Documentation

◆ addLogger()

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

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

◆ destroy()

void rwsf::LogManager::destroy ( )
static

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

◆ getLogger() [1/2]

Logger rwsf::LogManager::getLogger ( )
static

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

◆ getLogger() [2/2]

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

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).

◆ init()

void rwsf::LogManager::init ( )
static

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

◆ load()

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

Loads logger instances from a logger configuration file.

Exceptions
FileNotFoundExceptionis thrown if the file referenced by file cannot be found.

◆ removeLogger()

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

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.

◆ setDefault()

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

Sets the name of the default logger.

Copyright © 2026 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.