TrueReality  v0.1.1912
trUtil::Logging::Log Class Reference

Log class which the engine uses for all of its logging needs. More...

#include <Log.h>

Inheritance diagram for trUtil::Logging::Log:
Collaboration diagram for trUtil::Logging::Log:

Classes

struct  LogTestData
 A data structure that is used for Unit Tests. More...
 

Public Types

enum  OutputStreamOptions {
  NO_OUTPUT = 0x00000000, TO_FILE = 0x00000001, TO_CONSOLE = 0x00000002, TO_WRITER = 0x00000004,
  STANDARD = TO_FILE | TO_CONSOLE | TO_WRITER
}
 Values that represent output stream options. More...
 
using LogWriterContainer = std::vector< osg::ref_ptr< LogWriter > >
 The log writer container. More...
 

Public Member Functions

void LogMessage (const std::string &cppFile, const std::string &method, int line, const std::string &msg, LogLevel logLevel) const
 Logs a time-stamped message. More...
 
void LogMessage (LogLevel logLevel, const std::string &source, int line, const char *msg,...) const
 Little more sophisticated method for logging messages. More...
 
void LogMessage (LogLevel logLevel, const std::string &source, int line, const std::string &msg) const
 Little more sophisticated method for logging messages. More...
 
void LogMessage (LogLevel logLevel, const std::string &source, int line, const char *msg, va_list list) const
 Logs a time-stamped message. More...
 
void LogMessage (LogLevel logLevel, const std::string &source, const char *msg,...) const
 Little more sophisticated method for logging messages. More...
 
void LogHorizRule ()
 Inserts a horizontal rule into the log file. More...
 
bool IsLevelEnabled (LogLevel logLevel) const
 Queries if a level is enabled. More...
 
void SetLogLevel (LogLevel logLevel)
 Sets the lowest level of logging that will be logged. More...
 
LogLevel GetLogLevel () const
 Gets log level. More...
 
void AddWriter (LogWriter &writer)
 Add an writer that receives all log messages via callback. More...
 
void RemoveWriter (LogWriter &writer)
 Remove an existing LogWriter from the container. More...
 
const LogWriterContainerGetWriters () const
 Get all registered LogWriters that are registered to receive log messages. More...
 
LogWriterContainerGetWriters ()
 Get all registered LogWriters that are registered to receive log messages. More...
 
void SetOutputStreamBit (unsigned int option)
 Tell the Log where to send output messages. More...
 
unsigned int GetOutputStreamBit () const
 Get the currently defined output stream options. More...
 
const std::string & GetName () const
 Returns the name of this logger. More...
 
LogManagerGetLogManagerRef ()
 Returns a reference to the internal Log Manager. More...
 
void SetTestMode (bool state)
 Enables the use of unit test mode which enables capturing of certain data. More...
 
LogTestDataGetLastLogData () const
 Gets the last log data that was in the queue for testing. More...
 

Static Public Member Functions

static const std::string GetLogLevelString (LogLevel logLevel)
 Gets log level string. More...
 
static LogLevel GetLogLevelForString (const std::string &levelString)
 Gets log level for string. More...
 
static LogGetInstance (const std::string &name=Log::LOG_DEFAULT_NAME)
 Retrieve singleton instance of the log class for a give string name. More...
 
static void SetDefaultLogLevel (LogLevel newLevel)
 Sets the default LogLevel for new logs. More...
 
static void SetAllLogLevels (LogLevel newLevel)
 Set the LogLevel for all existing Log instances. More...
 
static void SetLogTimeProvider (LogTimeProvider *ltp)
 This sets a Log time source. More...
 
static void SetAllOutputStreamBits (unsigned int option)
 The same as above, but it sets the bits on ALL active log instances. More...
 

Static Public Attributes

static const std::string LOG_DEFAULT_NAME
 

Protected Member Functions

 Log (const std::string &name)
 Opens the log file and writes the html header information. More...
 
 ~Log ()
 Writes any closing html tags and closes the log file. More...
 

Private Attributes

LogImplmImpl
 
bool mTestingMode = false
 
LogTestData mLogTestData
 

Detailed Description

Log class which the engine uses for all of its logging needs.

The log file is formatted using html tags, therefore, any browser should display the log without any problems.

Definition at line 197 of file Log.h.

Member Typedef Documentation

◆ LogWriterContainer

using trUtil::Logging::Log::LogWriterContainer = std::vector<osg::ref_ptr<LogWriter> >

The log writer container.

Definition at line 425 of file Log.h.

Member Enumeration Documentation

◆ OutputStreamOptions

Values that represent output stream options.

Enumerator
NO_OUTPUT 
TO_FILE 
TO_CONSOLE 
TO_WRITER 
STANDARD 

Definition at line 450 of file Log.h.

Constructor & Destructor Documentation

◆ Log()

trUtil::Logging::Log::Log ( const std::string &  name)
protected

Opens the log file and writes the html header information.

All new logs are created with the global default log level.

Parameters
nameThe name.

Definition at line 71 of file Log.cpp.

Referenced by GetInstance().

Here is the caller graph for this function:

◆ ~Log()

trUtil::Logging::Log::~Log ( )
protected

Writes any closing html tags and closes the log file.

Definition at line 78 of file Log.cpp.

References mImpl.

Member Function Documentation

◆ AddWriter()

void trUtil::Logging::Log::AddWriter ( LogWriter writer)

Add an writer that receives all log messages via callback.

The TO_WRITER OutputStreamOptions bit must be set in order for LogWriters to get triggered.

See also
RemoveWriter()
Parameters
[in,out]writerThe LogWriter to register.
See also
SetOutputStreamBit()

Definition at line 328 of file Log.cpp.

References mImpl, and trUtil::Logging::LogImpl::mWriters.

◆ GetInstance()

Log & trUtil::Logging::Log::GetInstance ( const std::string &  name = Log::LOG_DEFAULT_NAME)
static

Retrieve singleton instance of the log class for a give string name.

WARNING: If the log instance does not exist yet, it will be created, but the creation is not thread safe. If you intend to use a log instance in multithreaded code, which I hope you do, make sure to create the instance ahead of time by calling get instance.

Parameters
name(Optional) The logger name.
Returns
The instance.

Definition at line 203 of file Log.cpp.

References Log(), and trUtil::Logging::LOG_MANAGER().

Referenced by trUtil::Exception::Exception(), trUtil::FileUtils::FileUtils(), trUtil::Exception::LogException(), trUtil::Logging::LogFile::SetFileName(), and trUtil::DefaultSettings::SetupLoggingOptions().

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

◆ GetLastLogData()

Log::LogTestData * trUtil::Logging::Log::GetLastLogData ( ) const

Gets the last log data that was in the queue for testing.

Returns
Null if it fails, else the last log data.

Definition at line 234 of file Log.cpp.

References trUtil::Logging::LOG_MANAGER(), and mLogTestData.

Here is the call graph for this function:

◆ GetLogLevel()

LogLevel trUtil::Logging::Log::GetLogLevel ( ) const

Gets log level.

Returns
the lowest level of logging that will be logged.

Definition at line 298 of file Log.cpp.

References mImpl, and trUtil::Logging::LogImpl::mLevel.

Referenced by trUtil::Logging::LoggingOff::LoggingOff().

Here is the caller graph for this function:

◆ GetLogLevelForString()

LogLevel trUtil::Logging::Log::GetLogLevelForString ( const std::string &  levelString)
static

Gets log level for string.

Parameters
levelStringThe level string.
Returns
the LogLevel matching a string or WARNING if there is no match.

Definition at line 253 of file Log.cpp.

References trUtil::Logging::LogLevelFromString().

Here is the call graph for this function:

◆ GetLogLevelString()

const std::string trUtil::Logging::Log::GetLogLevelString ( LogLevel  logLevel)
static

Gets log level string.

Parameters
logLevelThe log level.
Returns
a string version of a LogLevel.

Definition at line 247 of file Log.cpp.

References trUtil::Logging::LogLevelToString().

Referenced by trUtil::Logging::LogWriterConsole::LogMessage(), and trUtil::Logging::LogWriterFile::LogMessage().

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

◆ GetLogManagerRef()

LogManager & trUtil::Logging::Log::GetLogManagerRef ( )

Returns a reference to the internal Log Manager.

Returns
The log manager reference.

Definition at line 221 of file Log.cpp.

References trUtil::Logging::LOG_MANAGER().

Referenced by trUtil::Logging::LogFile::SetFileName().

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

◆ GetName()

const std::string & trUtil::Logging::Log::GetName ( ) const

Returns the name of this logger.

Returns
The name.

Definition at line 280 of file Log.cpp.

References mImpl, and trUtil::Logging::LogImpl::mName.

◆ GetOutputStreamBit()

unsigned int trUtil::Logging::Log::GetOutputStreamBit ( ) const

Get the currently defined output stream options.

Returns
The output stream bit.

Definition at line 274 of file Log.cpp.

References mImpl, and trUtil::Logging::LogImpl::mOutputStreamBit.

◆ GetWriters() [1/2]

const Log::LogWriterContainer & trUtil::Logging::Log::GetWriters ( ) const

Get all registered LogWriters that are registered to receive log messages.

Returns
The container of LogWriters (could be empty)

Definition at line 334 of file Log.cpp.

References mImpl, and trUtil::Logging::LogImpl::mWriters.

◆ GetWriters() [2/2]

Log::LogWriterContainer & trUtil::Logging::Log::GetWriters ( )

Get all registered LogWriters that are registered to receive log messages.

Returns
The container of LogWriters (could be empty)

Definition at line 340 of file Log.cpp.

References mImpl, and trUtil::Logging::LogImpl::mWriters.

◆ IsLevelEnabled()

bool trUtil::Logging::Log::IsLevelEnabled ( LogLevel  logLevel) const

Queries if a level is enabled.

Parameters
logLevelthe type of message to query about.
Returns
true if log messages of the given level will be sent to the log output.

Definition at line 286 of file Log.cpp.

References mImpl, and trUtil::Logging::LogImpl::mLevel.

Referenced by trUtil::FileUtils::ChangeDirectoryInternal(), trUtil::FileUtils::DirCopy(), trUtil::FileUtils::DirDelete(), trUtil::FileUtils::FileCopy(), trUtil::FileUtils::FileMove(), trUtil::FileUtils::InternalDirCopy(), trUtil::Exception::LogException(), trUtil::FileUtils::PopDirectory(), trUtil::FileUtils::PushDirectory(), and trUtil::FileUtils::RecursDeleteDir().

Here is the caller graph for this function:

◆ LogHorizRule()

void trUtil::Logging::Log::LogHorizRule ( )

Inserts a horizontal rule into the log file.

Definition at line 189 of file Log.cpp.

References trUtil::Bits::Has(), trUtil::Logging::LOG_MANAGER(), mImpl, trUtil::Logging::LogImpl::mOutputStreamBit, NO_OUTPUT, and TO_FILE.

Here is the call graph for this function:

◆ LogMessage() [1/5]

void trUtil::Logging::Log::LogMessage ( const std::string &  cppFile,
const std::string &  method,
int  line,
const std::string &  msg,
LogLevel  logLevel 
) const

Logs a time-stamped message.

Parameters
cppFileThe source file name which generated this message.
methodThe calling method which generated this message.
lineThe source code line number.
msgThe message to display.
logLevelLevel of message being displayed. (error,warning,info, etc)

Definition at line 85 of file Log.cpp.

References trUtil::Logging::LogWriter::LogData::file, trUtil::Logging::Log::LogTestData::file, trUtil::Logging::LogWriter::LogData::frameNumber, trUtil::Logging::Log::LogTestData::frameNumber, trUtil::Bits::Has(), trUtil::Logging::LogWriter::LogData::line, trUtil::Logging::Log::LogTestData::line, trUtil::Logging::LOG_MANAGER(), trUtil::Logging::LogWriter::LogData::logLevel, trUtil::Logging::Log::LogTestData::logLevel, trUtil::Logging::LogWriter::LogData::logName, trUtil::Logging::Log::LogTestData::logName, trUtil::Logging::LogWriter::LogData::method, trUtil::Logging::Log::LogTestData::method, mImpl, mLogTestData, trUtil::Logging::LogImpl::mName, trUtil::Logging::LogImpl::mOutputStreamBit, trUtil::Logging::LogWriter::LogData::msg, trUtil::Logging::Log::LogTestData::msg, mTestingMode, trUtil::Logging::LogImpl::mWriters, NO_OUTPUT, trUtil::DateTime::SetToLocalTime(), trUtil::Logging::LogWriter::LogData::time, trUtil::Logging::Log::LogTestData::time, TO_CONSOLE, TO_FILE, and TO_WRITER.

Referenced by trUtil::FileUtils::ChangeDirectoryInternal(), trUtil::FileUtils::DirCopy(), trUtil::FileUtils::DirDelete(), trUtil::FileUtils::FileCopy(), trUtil::FileUtils::FileMove(), trUtil::FileUtils::InternalDirCopy(), trUtil::Exception::LogException(), LogMessage(), trUtil::FileUtils::PopDirectory(), trUtil::FileUtils::PushDirectory(), and trUtil::FileUtils::RecursDeleteDir().

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

◆ LogMessage() [2/5]

void trUtil::Logging::Log::LogMessage ( LogLevel  logLevel,
const std::string &  source,
int  line,
const char *  msg,
  ... 
) const

Little more sophisticated method for logging messages.

Allows for an unlimited number of parameters in a C-style printf syntax.

Parameters
logLevel- Type of message being displayed. (error,warning,info)
source- String identifier of the source of the message.
line- the line number.
msg- Printf - style format string.
Note
Max length of the string to be printed is 2048 characters.
Parameters
...Variable arguments providing additional information.

Definition at line 173 of file Log.cpp.

References LogMessage().

Here is the call graph for this function:

◆ LogMessage() [3/5]

void trUtil::Logging::Log::LogMessage ( LogLevel  logLevel,
const std::string &  source,
int  line,
const std::string &  msg 
) const

Little more sophisticated method for logging messages.

Allows for an unlimited number of parameters in a C-style printf syntax.

Parameters
logLevel- Type of message being displayed. (error,warning,info)
source- String identifier of the source of the message.
line- the line number.
msg- std::string that has been formatted.
Note
Max length of the string to be printed is 2048 characters.

Definition at line 183 of file Log.cpp.

References LogMessage().

Here is the call graph for this function:

◆ LogMessage() [4/5]

void trUtil::Logging::Log::LogMessage ( LogLevel  logLevel,
const std::string &  source,
int  line,
const char *  msg,
va_list  list 
) const

Logs a time-stamped message.

Takes a variable-argument list (va_list) that was created with va_start.

Parameters
logLevel- Type of message being displayed. (error,warning,info)
source- String identifier of the source of the message.
line- line number or negative for unknown.
msg- Printf - style format string.
list- va_list created with va_start.
Note
Max length of the string to be printed is 2048 characters.

Definition at line 153 of file Log.cpp.

References LogMessage().

Here is the call graph for this function:

◆ LogMessage() [5/5]

void trUtil::Logging::Log::LogMessage ( LogLevel  logLevel,
const std::string &  source,
const char *  msg,
  ... 
) const

Little more sophisticated method for logging messages.

Allows for an unlimited number of parameters in a C-style printf syntax.

Parameters
logLevel- Type of message being displayed. (error,warning,info)
source- String identifier of the source of the message.
msg- Printf - style format string.
Note
Max length of the string to be printed is 2048 characters.
Parameters
...Variable arguments providing additional information.

Definition at line 163 of file Log.cpp.

References LogMessage().

Here is the call graph for this function:

◆ RemoveWriter()

void trUtil::Logging::Log::RemoveWriter ( LogWriter writer)

Remove an existing LogWriter from the container.

Parameters
[in,out]writerThe LogWriter to remove.
See also
AddWriter()

Definition at line 346 of file Log.cpp.

References mImpl, and trUtil::Logging::LogImpl::mWriters.

◆ SetAllLogLevels()

void trUtil::Logging::Log::SetAllLogLevels ( LogLevel  newLevel)
static

Set the LogLevel for all existing Log instances.

Parameters
newLevelThe new level.
See also
SetLogLevel()

Definition at line 304 of file Log.cpp.

References trUtil::Logging::LOG_MANAGER().

Referenced by trUtil::DefaultSettings::SetupLoggingOptions().

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

◆ SetAllOutputStreamBits()

void trUtil::Logging::Log::SetAllOutputStreamBits ( unsigned int  option)
static

The same as above, but it sets the bits on ALL active log instances.

Parameters
optionThe option.

Definition at line 265 of file Log.cpp.

References trUtil::Logging::LOG_MANAGER().

Referenced by trUtil::DefaultSettings::SetupLoggingOptions().

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

◆ SetDefaultLogLevel()

void trUtil::Logging::Log::SetDefaultLogLevel ( LogLevel  newLevel)
static

Sets the default LogLevel for new logs.

Parameters
newLevelThe new level.

Definition at line 241 of file Log.cpp.

References trUtil::Logging::DEFAULT_LOG_LEVEL().

Here is the call graph for this function:

◆ SetLogLevel()

void trUtil::Logging::Log::SetLogLevel ( LogLevel  logLevel)

Sets the lowest level of logging that will be logged.

If the level in set to Debug, all messages will be sent. If the level is set error, only errors will be sent.

Parameters
logLevelthe new logging level.

Definition at line 292 of file Log.cpp.

References mImpl, and trUtil::Logging::LogImpl::mLevel.

Referenced by trUtil::Logging::LoggingOff::LoggingOff(), trUtil::Logging::LogManager::SetAllLogLevels(), and trUtil::Logging::LoggingOff::~LoggingOff().

Here is the caller graph for this function:

◆ SetLogTimeProvider()

void trUtil::Logging::Log::SetLogTimeProvider ( LogTimeProvider ltp)
static

This sets a Log time source.

This allows another part of the system to update and provide both a time and a frame number, as needed. Otherwise, the time will be set on the log data every time log is called.

Parameters
[in,out]ltpIf non-null, the ltp.

Definition at line 313 of file Log.cpp.

References LOG_E, and trUtil::Logging::LOG_MANAGER().

Here is the call graph for this function:

◆ SetOutputStreamBit()

void trUtil::Logging::Log::SetOutputStreamBit ( unsigned int  option)

Tell the Log where to send output messages.

The supplied parameter is a bitwise combination of OutputStreamOptions. The default is STANDARD, which directs messages to both the console and the output file. For example, to tell the Log to output to the file and console:

Parameters
optionA bitwise combination of options.
optionThe option.

Definition at line 259 of file Log.cpp.

References mImpl, and trUtil::Logging::LogImpl::mOutputStreamBit.

Referenced by trUtil::Logging::LogManager::SetAllOutputStreamBits().

Here is the caller graph for this function:

◆ SetTestMode()

void trUtil::Logging::Log::SetTestMode ( bool  state)

Enables the use of unit test mode which enables capturing of certain data.

Parameters
stateTrue to state.

Definition at line 227 of file Log.cpp.

References trUtil::Logging::LOG_MANAGER(), and mTestingMode.

Here is the call graph for this function:

Member Data Documentation

◆ LOG_DEFAULT_NAME

const std::string trUtil::Logging::Log::LOG_DEFAULT_NAME
static

Definition at line 218 of file Log.h.

◆ mImpl

◆ mLogTestData

LogTestData trUtil::Logging::Log::mLogTestData
mutableprivate

Definition at line 551 of file Log.h.

Referenced by GetLastLogData(), and LogMessage().

◆ mTestingMode

bool trUtil::Logging::Log::mTestingMode = false
private

Definition at line 550 of file Log.h.

Referenced by LogMessage(), and SetTestMode().


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