xoreos  0.0.5
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Attributes | List of all members
Common::DebugManager Class Reference

The debug manager, managing debug channels. More...

#include <debugman.h>

Inheritance diagram for Common::DebugManager:
Inheritance graph
[legend]
Collaboration diagram for Common::DebugManager:
Collaboration graph
[legend]

Classes

struct  Channel
 A debug channel. More...
 

Public Member Functions

 DebugManager ()
 
 ~DebugManager ()
 
void getDebugChannels (std::vector< UString > &names, std::vector< UString > &descriptions) const
 Return the channel names alongside their descriptions. More...
 
void setVerbosityLevel (DebugChannel channel, uint32 level)
 Set the verbosity level of this channel (by ID). More...
 
void setVerbosityLevel (const UString &channel, uint32 level)
 Set the verbosity level of this channel (by name). More...
 
uint32 getVerbosityLevel (DebugChannel channel) const
 Return the verbosity level of this channel (by ID). More...
 
uint32 getVerbosityLevel (const UString &channel) const
 Return the verbosity level of this channel (by name). More...
 
bool isEnabled (DebugChannel channel, uint32 level) const
 Is this channel ID enabled for this verbosity level? More...
 
bool isEnabled (const UString &channel, uint32 level) const
 Is this channel name enabled for this verbosity level? More...
 
void setVerbosityLevelsFromConfig ()
 Sync verbosity levels from the ConfigManager. More...
 
void setConfigToVerbosityLevels ()
 Sync verbosity levels to the ConfigManager. More...
 
void logDebugGL (DebugChannel channel, uint32 level, DebugGLType type, uint32 id, const char *msg)
 Log (and print) an OpenGL debug message. More...
 
bool openLogFile (const UString &file)
 Open a log file where all debug output will be written to. More...
 
void closeLogFile ()
 Close the current log file. More...
 
void logString (const UString &str)
 Log that string to the current log file. More...
 
void logCommandLine (const std::vector< UString > &argv)
 Write the whole command line to the current log file. More...
 

Static Public Member Functions

static UString getDefaultLogFile ()
 Return the OS-specific default path of the log file. More...
 
- Static Public Member Functions inherited from Common::Singleton< DebugManager >
static DebugManagerinstance ()
 
static void destroy ()
 

Static Public Attributes

static const uint32 kMaxVerbosityLevel = 9
 

Private Types

typedef std::map< UString, DebugChannel, UString::ilessChannelMap
 

Private Attributes

Channel _channels [kDebugChannelCount]
 All debug channels. More...
 
ChannelMap _channelMap
 Debug channels indexed by name. More...
 
WriteFile _logFile
 
bool _logFileStartLine
 
bool _changedConfig
 

Additional Inherited Members

- Protected Types inherited from Common::Singleton< DebugManager >
typedef DebugManager SingletonBaseType
 
- Protected Member Functions inherited from Common::Singleton< DebugManager >
 Singleton ()
 
virtual ~Singleton ()
 

Detailed Description

The debug manager, managing debug channels.

A debug channel separates debug messages into groups, so debug output doesn't get swamped unnecessarily.

Each debug channel is associated with a verbosity "level" at which it is currently enabled, and each debug message is sent to a channel with a number specifying its verbosity level. The debug message is then only shown when the debug channel it belongs to is enabled at a verbosity level equal to or higher than the debug message's verbosity level.

The verbosity levels go from 0 (disabled) to 9 (most verbose).

For example:

There are two debug channels, C1 and C2. C1 is enabled at verbosity level 3 and C2 is enabled at verbosity level 0 (i.e. disabled). These three debug messages arrive: 1) Channel C1, level 3 2) Channel C1, level 4 3) Channel C2, level 1

In this scenario, only message 1, the one at channel C1 with a level of 3 is shown. Message 2 is not shown, because with a level of 4 it exceeds the current level of C1, which is 3. Likewise, the level of message 3, 1, exceeds the current level of C2. In fact, with a current level of 0, no messages will be shown for C2 at all, ever.

Definition at line 108 of file debugman.h.

Member Typedef Documentation

◆ ChannelMap

Definition at line 181 of file debugman.h.

Constructor & Destructor Documentation

◆ DebugManager()

Common::DebugManager::DebugManager ( )

◆ ~DebugManager()

Common::DebugManager::~DebugManager ( )

Definition at line 87 of file debugman.cpp.

References closeLogFile().

Here is the call graph for this function:

Member Function Documentation

◆ closeLogFile()

void Common::DebugManager::closeLogFile ( )

Close the current log file.

Definition at line 243 of file debugman.cpp.

References _logFile, and Common::WriteFile::close().

Referenced by openLogFile(), and ~DebugManager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDebugChannels()

void Common::DebugManager::getDebugChannels ( std::vector< UString > &  names,
std::vector< UString > &  descriptions 
) const

Return the channel names alongside their descriptions.

Definition at line 91 of file debugman.cpp.

References _channels, Common::DebugManager::Channel::description, Common::kDebugChannelCount, and Common::DebugManager::Channel::name.

◆ getDefaultLogFile()

UString Common::DebugManager::getDefaultLogFile ( )
static

Return the OS-specific default path of the log file.

Definition at line 287 of file debugman.cpp.

References Common::FilePath::getUserDataDirectory().

Here is the call graph for this function:

◆ getVerbosityLevel() [1/2]

uint32 Common::DebugManager::getVerbosityLevel ( DebugChannel  channel) const

Return the verbosity level of this channel (by ID).

Definition at line 128 of file debugman.cpp.

References _channels, Common::kDebugChannelCount, and Common::DebugManager::Channel::level.

Referenced by getVerbosityLevel(), and isEnabled().

Here is the caller graph for this function:

◆ getVerbosityLevel() [2/2]

uint32 Common::DebugManager::getVerbosityLevel ( const UString channel) const

Return the verbosity level of this channel (by name).

Definition at line 135 of file debugman.cpp.

References _channelMap, and getVerbosityLevel().

Here is the call graph for this function:

◆ isEnabled() [1/2]

bool Common::DebugManager::isEnabled ( DebugChannel  channel,
uint32  level 
) const

Is this channel ID enabled for this verbosity level?

Definition at line 143 of file debugman.cpp.

References getVerbosityLevel(), and kMaxVerbosityLevel.

Referenced by logDebugGL().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isEnabled() [2/2]

bool Common::DebugManager::isEnabled ( const UString channel,
uint32  level 
) const

Is this channel name enabled for this verbosity level?

Definition at line 147 of file debugman.cpp.

References getVerbosityLevel(), and kMaxVerbosityLevel.

Here is the call graph for this function:

◆ logCommandLine()

void Common::DebugManager::logCommandLine ( const std::vector< UString > &  argv)

Write the whole command line to the current log file.

Definition at line 278 of file debugman.cpp.

References logString().

Here is the call graph for this function:

◆ logDebugGL()

void Common::DebugManager::logDebugGL ( DebugChannel  channel,
uint32  level,
DebugGLType  type,
uint32  id,
const char *  msg 
)

Log (and print) an OpenGL debug message.

Definition at line 202 of file debugman.cpp.

References _channels, Common::DebugManager::Channel::glTypeIDs, isEnabled(), Common::isOpenGLDebugChannel(), Common::kDebugGLTypeMAX, Common::kDebugGLTypeOther, Common::kDebugGLTypes, Common::kDebugNames, and status().

Here is the call graph for this function:

◆ logString()

void Common::DebugManager::logString ( const UString str)

Log that string to the current log file.

Definition at line 247 of file debugman.cpp.

References _logFile, _logFileStartLine, Common::UString::empty(), Common::UString::end(), Common::WriteFile::flush(), Common::DateTime::formatDateTimeISO(), Common::WriteFile::isOpen(), Common::DateTime::kUTC, and Common::WriteStream::writeString().

Referenced by logCommandLine(), and openLogFile().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ openLogFile()

bool Common::DebugManager::openLogFile ( const UString file)

Open a log file where all debug output will be written to.

For ease of debugging and build identification, the xoreos version string will be the first line written to the file.

Definition at line 220 of file debugman.cpp.

References _logFile, _logFileStartLine, Common::FilePath::canonicalize(), closeLogFile(), Common::FilePath::createDirectories(), Common::FilePath::getDirectory(), Version::getProjectNameVersionFull(), logString(), and Common::WriteFile::open().

Here is the call graph for this function:

◆ setConfigToVerbosityLevels()

void Common::DebugManager::setConfigToVerbosityLevels ( )

Sync verbosity levels to the ConfigManager.

This writes the current verbosity levels of all debug channels into the "debug" config option of the ConfigManager.

Definition at line 179 of file debugman.cpp.

References _changedConfig, _channels, Common::composeString(), ConfigMan, Common::UString::empty(), Common::kDebugChannelCount, and Common::DebugManager::Channel::name.

Here is the call graph for this function:

◆ setVerbosityLevel() [1/2]

void Common::DebugManager::setVerbosityLevel ( DebugChannel  channel,
uint32  level 
)

Set the verbosity level of this channel (by ID).

Definition at line 101 of file debugman.cpp.

References _changedConfig, _channels, Common::kDebugChannelAll, Common::kDebugChannelCount, Common::kDebugGLTypeMAX, kMaxVerbosityLevel, and Common::DebugManager::Channel::level.

Referenced by setVerbosityLevel(), and setVerbosityLevelsFromConfig().

Here is the caller graph for this function:

◆ setVerbosityLevel() [2/2]

void Common::DebugManager::setVerbosityLevel ( const UString channel,
uint32  level 
)

Set the verbosity level of this channel (by name).

Definition at line 120 of file debugman.cpp.

References _channelMap, and setVerbosityLevel().

Here is the call graph for this function:

◆ setVerbosityLevelsFromConfig()

void Common::DebugManager::setVerbosityLevelsFromConfig ( )

Sync verbosity levels from the ConfigManager.

This reads the current value of the "debug" config option from the ConfigManager, parses it, and sets the verbosity levels of all debug channels according to this value.

Definition at line 151 of file debugman.cpp.

References _changedConfig, ConfigMan, Common::kDebugChannelAll, Common::parseString(), setVerbosityLevel(), and Common::UString::split().

Here is the call graph for this function:

Member Data Documentation

◆ _changedConfig

bool Common::DebugManager::_changedConfig
private

◆ _channelMap

ChannelMap Common::DebugManager::_channelMap
private

Debug channels indexed by name.

Definition at line 184 of file debugman.h.

Referenced by DebugManager(), getVerbosityLevel(), and setVerbosityLevel().

◆ _channels

Channel Common::DebugManager::_channels[kDebugChannelCount]
private

◆ _logFile

WriteFile Common::DebugManager::_logFile
private

Definition at line 186 of file debugman.h.

Referenced by closeLogFile(), logString(), and openLogFile().

◆ _logFileStartLine

bool Common::DebugManager::_logFileStartLine
private

Definition at line 187 of file debugman.h.

Referenced by logString(), and openLogFile().

◆ kMaxVerbosityLevel

const uint32 Common::DebugManager::kMaxVerbosityLevel = 9
static

Definition at line 110 of file debugman.h.

Referenced by isEnabled(), and setVerbosityLevel().


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