# Logger Class Reference

Central object of the logging system. More...

`#include <Logger.h>`

List of all members.

## Public Member Functions
| Logger ()
| Constructor.
| ~Logger ()
| Destructor. Deletes all LogFilters, ILogPrinters and ILogManagers created during construction.
void | Log (const LogInfo &logInfo, const CompositeLoggable &message)
| Logs the message into the logging system.
LogLevel | GetMaximumLogLevel (const std::tstring &scopeLoggerName)
| Returns the maximum LogLevel for which there is at least one LogFilter which doesn't filter out messages from ScopeLogger named "scopeLoggerName".
## Static Public Member Functions
static Logger & | GetLogger ()
| Static function returning the static instance of Logger.
## Private Member Functions
bool | TryConfigureFromRegistry (HKEY baseKeyHandle, const std::tstring &processName)
| Configures this Logger using configuration stored under particular base registry key.
void | ConfigureDefault ()
| Configures this Logger using default, "hardcoded" configuration.
void | ConfigureLogChannel (const std::tstring &logFilterName, const std::tstring &logPrinterName, const std::set< std::tstring > &logManagers, const RegistryKey &definitionsKey)
| Configures the LogChannel.
ILogPrinter * | CreateLogPrinter (const RegistryKey &key) const
| Creates and returns a new ILogPrinter instance.
ILogManager * | CreateLogManager (const RegistryKey &key) const
| Creates and returns a new ILogManager instance.
ILogManager * | GetOrCreateLogManager (const std::tstring &name, const RegistryKey &key)
| Returns a existing LogManager with specified name, or creates a new one if it doesn't exist.
std::tstring | GetProcessName ()
| Returns the name of the executable file of this process.
## Private Attributes
std::vector< std::pair < LogFilter *, ILogPrinter * > > | FiltersAndPrinters
| Vector containing LogFilters and ILogPrinters present in the system.
std::map< std::tstring, ILogManager * > | Managers
| Map containing ILogManager&s present in the system, keyed by their names.
## Friends
class | Nvidia::Logging::Test::LoggerTest
class | Nvidia::Logging::Test::LoggerConstructorTest

## Detailed Description

Central object of the logging system.

Logger manages all ILogPrinters, LogFilters and ILogManagers present in the system. It also acts as a collector and distributor of the log messages - messages from all ScopeLoggers are passed to Logger via Log() function, and all LogPrinters retrieve the filtered messages from Logger.

There should be only one instance of the Logger object per process. This instance can be accessed using _GetLogger() function.

Definition at line 78 of file Logger.h.

## Constructor & Destructor Documentation

Logger | ( |  | ) | `[inline]`

Constructor.

Current implementation tries to configure the logging system using configuration stored in registry, trying the keys in following order:

- HKEY_CURRENT_USER/Software/NVIDIA Corporation/Logging/(this process name)/
- HKEY_LOCAL_MACHINE/Software/NVIDIA Corporation/Logging/(this process name)/
- HKEY_CURRENT_USER/Software/NVIDIA Corporation/Logging/DefaultProcess/
- HKEY_LOCAL_MACHINE/Software/NVIDIA Corporation/Logging/DefaultProcess/

If all of the above fail (due to either unavailability of the key or its invalid structure), then "hardcoded" default configuration is used.

Definition at line 251 of file Logger.h.

References Logger::ConfigureDefault(), Logger::GetProcessName(), and Logger::TryConfigureFromRegistry().

## Member Function Documentation

void ConfigureDefault | ( |  | ) | `[inline, private]`

Configures this Logger using default, "hardcoded" configuration.

The default configuration contains one LogChannel consisting of:

- LogFilter filtering out any messages above Warning LogLevel,
- SimpleTextLogPrinter,
- DebugOutputLogManager.

Definition at line 287 of file Logger.h.

References ILogPrinter::AddLogManager(), Logger::FiltersAndPrinters, and Logger::Managers.

Referenced by Logger::Logger().

void ConfigureLogChannel | ( | const std::tstring & | logFilterName,
|  | const std::tstring & | logPrinterName,
|  | const std::set< std::tstring > & | logManagers,
|  | const RegistryKey & | definitionsKey |
| ) |  |  | `[inline, private]`

Configures the LogChannel.

Current implementation follows this algorithm:

- Try to create the LogFilter. If unsuccessful - silently fail.
- Try to create the ILogPrinter using CreateLogPrinter(). If unsuccessful - destroy the LogFilter created in previous step and silently fail.
- For each element of logManagers
  - Try to create or retrieve an existing instance of ILogManager using GetOrCreateLogManager(). If unsuccessful - move on to next logManagers element.
  - Try to add the new ILogManager to the ILogPrinter. If unsuccessful - move on to next logManagers element. This particular step doesn't require destruction of the unused LogManager because it was saved in Managers container by GetOrCreateLogManager() and will be destroyed in ~Logger().

Parameters:

  | logFilterName | Name of the LogFilter in this LogChannel.
  | logPrinterName | Name of the ILogPrinter in this LogChannel.
  | logManagers | Set of names of the ILogManagers in this LogChannel.
  | definitionsKey | The registry key containing the definitions of LogChannel elements.

Definition at line 333 of file Logger.h.

References ILogPrinter::AddLogManager(), Logger::CreateLogPrinter(), Logger::FiltersAndPrinters, and Logger::GetOrCreateLogManager().

Referenced by Logger::TryConfigureFromRegistry().

ILogManager * CreateLogManager | ( | const RegistryKey & | key | ) | const`[inline, private]`

Creates and returns a new ILogManager instance.

This method reads the className value of the passed registry key and executes appropriate constructor according to it. Contents of this method should be changed when new ILogManager implementation is written.

Parameters:

  | key | Registry key containing the configuration of this ILogManager.

Exceptions:

  | std::runtime_error | When the requested ILogManager implementation wasn't found.
  | std::exception | When the particular ILogManager constructor failed.

Definition at line 381 of file Logger.h.

Referenced by Logger::GetOrCreateLogManager().

ILogPrinter * CreateLogPrinter | ( | const RegistryKey & | key | ) | const`[inline, private]`

Creates and returns a new ILogPrinter instance.

This method reads the className value of the passed registry key and executes appropriate constructor according to it. Contents of this method should be changed when new ILogPrinter implementation is written.

Parameters:

  | key | Registry key containing the configuration of ILogPrinter.

Exceptions:

  | std::runtime_error | When the requested ILogPrinter implementation wasn't found.
  | std::exception | When the particular ILogPrinter constructor failed.

Definition at line 363 of file Logger.h.

Referenced by Logger::ConfigureLogChannel().

Logger & GetLogger | ( |  | ) | `[inline, static]`

Static function returning the static instance of Logger.

We need this function instead of a static instance to prevent the so-called "static initialization order fiasco".

Definition at line 451 of file Logger.h.

Referenced by ScopeLogger::Log().

LogLevel GetMaximumLogLevel | ( | const std::tstring & | scopeLoggerName | ) | `[inline]`

Returns the maximum LogLevel for which there is at least one LogFilter which doesn't filter out messages from ScopeLogger named "scopeLoggerName".

This method is used by the ScopeLogger to determine which messages won't be accepted by any of the registered LogFilters and thus can be filtered out before they are even created. Logic of that filtering is contained in LOG() and LOGF() macros.

Definition at line 435 of file Logger.h.

References Logger::FiltersAndPrinters, and LogFilter::GetMaximumLogLevel().

ILogManager * GetOrCreateLogManager | ( | const std::tstring & | name,
|  | const RegistryKey & | key |
| ) |  |  | `[inline, private]`

Returns a existing LogManager with specified name, or creates a new one if it doesn't exist.

If a new ILogManager instance had to be created, it is saved in Managers container to allow its reuse in other LogChannels, and destruction in ~Logger().

Parameters:

  | key | Registry key containing the configuration of this ILogManager.

Exceptions:

  | std::exception | When creating the ILogManager failed.

Definition at line 399 of file Logger.h.

References Logger::CreateLogManager(), and Logger::Managers.

Referenced by Logger::ConfigureLogChannel().

std::tstring GetProcessName | ( |  | ) | `[inline, private]`

Returns the name of the executable file of this process.

The returned string is generated by cutting out the directory part from the result of GetModuleFileName() system call.

Definition at line 278 of file Logger.h.

Referenced by Logger::Logger().

void Log | ( | const LogInfo & | logInfo,
|  | const CompositeLoggable & | message |
| ) |  |  | `[inline]`

Logs the message into the logging system.

This method passes the LogInfo instance to each of the LogFilters registered in the FiltersAndPrinters container, via LogFilter::isFiltered(LogInfo) method. For each LogFilter that returned false from that method, the logInfo together with the message is passed to PrintMessage method of the ILogPrinter paired with that LogFilter.

Definition at line 425 of file Logger.h.

References Logger::FiltersAndPrinters.

Referenced by ScopeLogger::Log().

bool TryConfigureFromRegistry | ( | HKEY | baseKeyHandle,
|  | const std::tstring & | processName |
| ) |  |  | `[inline, private]`

Configures this Logger using configuration stored under particular base registry key.

Current implementation will first determine whether the structure of the Software/NVIDIA Corporation/Logging subkey is valid. False will be returned if this is not the case. Then the configuration for each of the LogChannels referenced in configuration of this process will be read, and the elements of the LogChannel will be created by ConfigureLogChannel(). No exceptions are thrown during this phase. Any error occurring during processing of particular LogChannel will cause this LogChannel to be ignored.

Parameters:

  | baseKeyHandle | Open key handle for the base key. This should be either HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE.
  | processName | Name of the process whose configuration should be read.

Returns:
  Boolean value indicating whether the configuration was applied.

Definition at line 298 of file Logger.h.

References Logger::ConfigureLogChannel().

Referenced by Logger::Logger().

## Member Data Documentation

std::vector<std::pair<LogFilter*, ILogPrinter*> > FiltersAndPrinters`[private]`

Vector containing LogFilters and ILogPrinters present in the system.

The pairing between LogFilter and ILogPrinter is determined by the configuration in the registry - for each LogChannel defined in the configuration for this process there will be one pair of LogFilter and ILogPrinter from that LogChannel in this Vector.

The definitions for LogFilters and ILogPrinters in the registry configuration are treated only as instructions on how to create particular LogFilter or ILogPrinter. In practice this means that if a LogFilter or ILogPrinter definition is referenced twice from different LogChannel definitions, then two instances of LogFilter or ILogPrinter will be created. This is in contrast to the ILogManagers management, where only one ILogManager is created for each definition in configuration.

Definition at line 98 of file Logger.h.

Referenced by Logger::ConfigureDefault(), Logger::ConfigureLogChannel(), Logger::GetMaximumLogLevel(), Logger::Log(), and Logger::~Logger().

std::map<std::tstring, ILogManager*> Managers`[private]`

Map containing ILogManager&s present in the system, keyed by their names.

Only ILogManagers referenced from LogChannels attached to this process are created and stored in this map.

Definition at line 106 of file Logger.h.

Referenced by Logger::ConfigureDefault(), Logger::GetOrCreateLogManager(), and Logger::~Logger().

The documentation for this class was generated from the following file:

- Logger.h