GCF LOGO VCL LOGO

This class offers means to log a hierarchy of messages and process them. More...

#include <GCF3/Log>

Public Member Functions

void setHandler (GCF::LogMessageHandlerInterface *handler)
 
GCF::LogMessageHandlerInterfacehandler () const
 
void setLogFileName (const QString &logFileName)
 
QString logFileName () const
 
void setLogQtMessages (bool val)
 
bool isLogQtMessages () const
 
void fatal (const QString &context, const QString &message, const QString &details=QString())
 
void fatal (const QString &context, const QByteArray &errorCode, const QString &message, const QString &details)
 
void error (const QString &context, const QString &message, const QString &details=QString())
 
void error (const QString &context, const QByteArray &errorCode, const QString &message, const QString &details)
 
void warning (const QString &context, const QString &message, const QString &details=QString())
 
void warning (const QString &context, const QByteArray &errorCode, const QString &message, const QString &details)
 
void debug (const QString &context, const QString &message, const QString &details=QString())
 
void debug (const QString &context, const QByteArray &errorCode, const QString &message, const QString &details)
 
void info (const QString &context, const QString &message, const QString &details=QString())
 
void info (const QString &context, const QByteArray &errorCode, const QString &message, const QString &details)
 
QList< GCF::LogMessage * > logMessages () const
 
QString toString () const
 
void copyToClipboard ()
 
void copyToSupport ()
 
void handleLogMessage (GCF::LogMessage *msg)
 
void print (GCF::LogMessage *msg, QTextStream &ts)
 
- Public Member Functions inherited from GCF::LogMessageHandlerInterface
virtual void toSupport (const QString &msg)
 
virtual void toClipboard (const QString &msg)
 
virtual void flush ()
 

Static Public Member Functions

static Loginstance ()
 

Detailed Description

This is the only singleton class in all of GCF3. Through this single instance, users can log warning, debug, error and info messages. Although actual logging takes place via GCF::LogMessageHandlerInterface, set using setHandler() method; this class offers a simple API for feeding log messages and passing the buck to the handler when appropriate. By default an internal log-handler is registered as handler with GCF::Log; which dumps all log messages to a log file. You can enable logging of qDebug(), qWarning(), qFatal() and qCritical() messages by calling setLogQtMessages() method. Logging can be done from multiple threads as well. Forwarded calls to GCF::LogMessageHandlerInterface are serialized.

Usage:

void function()
{
GCF::Log::instance()->info(GCF_DEFAULT_LOG_CONTEXT, "Simple log message");
}

The GCF_DEFAULT_LOG_CONTEXT constructs a default-context string based on the current function and line-number. Contexts help in figuring out where the log message has originated. You can use GCF_DEFAULT_LOG_CONTEXT or any other context string of your choice.

Each message dumped via info(), debug(), warning(), error(), and fatal() is stored as a GCF::LogMessage until the handler() handles the message. After the message is handled, it gets deleted.

Logs can be hierarchical. You can create a log-hierarchy by creating instances of the GCF::LogMessageBranch class. Branches are internally treated as log messages. Example:

void anotherFunction();
void yetAnotherFunction();
void function()
{
GCF::LogMessageBranch branch("function() branch");
::anotherFunction();
::yetAnotherFunction();
}
void anotherFunction()
{
GCF::Log::instance()->info(GCF_DEFAULT_LOG_CONTEXT, "Simple log message");
}
void yetAnotherFunction()
{
GCF::Log::instance()->info(GCF_DEFAULT_LOG_CONTEXT, "Simple log message");
}

In the above example, log messages from anotherFunction() and yetAnotherFunction() are dumped into the log branch created within function(). When the log messages are dumped on to a log-file (or shown in a dialog box); the hierarchy is captured using indentation (or tree-view).

Hierarchichal logs are useful to understand the context in which a log message arose. For example, it might be useful to know whether the log message generated by yetAnotherFunction() happened in the context of a function() call or a direct call.

Note
Branches that have no log messages are automatically deleted.
Branches or messages, once dumped into the log file are automatically deleted.
See Also
GCF::LogMessage

Member Function Documentation

GCF::Log * GCF::Log::instance ( )
static
Returns
pointer to the only instance of this class in the application
void GCF::Log::setHandler ( GCF::LogMessageHandlerInterface handler)

Sets the handler to which all log messages are forwarded.

Parameters
handlerpointer to the handler. If null, the default internal handler is used.
GCF::LogMessageHandlerInterface * GCF::Log::handler ( ) const
Returns
pointer to the handler used by the log
void GCF::Log::setLogFileName ( const QString &  logFile)

Sets the file-name into which all logs are dumped by the default handler.

Parameters
logFilename of the file into which log messages are dumped by the default handler
QString GCF::Log::logFileName ( ) const
Returns
complete path to the file into which log messages are dumped by the default handler.
void GCF::Log::setLogQtMessages ( bool  val)

This function can be used to enable/disable logging of qDebug(), qWarning(), qFatal() and qCritical() messages to the log. By default logging of QtDebug messages is disabled.

Parameters
valtrue if QtDebug messages need to be logged, false otherwise.
bool GCF::Log::isLogQtMessages ( ) const
Returns
true if QtDebug messages are logged. False otherwise.
See Also
setLogQtMessages()
void GCF::Log::fatal ( const QString &  context,
const QString &  message,
const QString &  details = QString() 
)

Logs a fatal message into the current branch

Parameters
contexta string representing the context of the message. Use of GCF_DEFAULT_LOG_CONTEXT for this parameter is recommended
messagea brief one liner associated with this message
detailsa detailed multi-line text associated with this message
void GCF::Log::fatal ( const QString &  context,
const QByteArray &  errorCode,
const QString &  message,
const QString &  details 
)

Logs a fatal message into the current branch

Parameters
contexta string representing the context of the message. Use of GCF_DEFAULT_LOG_CONTEXT for this parameter is recommended
errorCodea code associated with this message
messagea brief one liner associated with this message
detailsa detailed multi-line text associated with this message
void GCF::Log::error ( const QString &  context,
const QString &  message,
const QString &  details = QString() 
)

Logs a error message into the current branch

Parameters
contexta string representing the context of the message. Use of GCF_DEFAULT_LOG_CONTEXT for this parameter is recommended
messagea brief one liner associated with this message
detailsa detailed multi-line text associated with this message
void GCF::Log::error ( const QString &  context,
const QByteArray &  errorCode,
const QString &  message,
const QString &  details 
)

Logs a error message into the current branch

Parameters
contexta string representing the context of the message. Use of GCF_DEFAULT_LOG_CONTEXT for this parameter is recommended
errorCodea code associated with this message
messagea brief one liner associated with this message
detailsa detailed multi-line text associated with this message
void GCF::Log::warning ( const QString &  context,
const QString &  message,
const QString &  details = QString() 
)

Logs a warning message into the current branch

Parameters
contexta string representing the context of the message. Use of GCF_DEFAULT_LOG_CONTEXT for this parameter is recommended
messagea brief one liner associated with this message
detailsa detailed multi-line text associated with this message
void GCF::Log::warning ( const QString &  context,
const QByteArray &  errorCode,
const QString &  message,
const QString &  details 
)

Logs a warning message into the current branch

Parameters
contexta string representing the context of the message. Use of GCF_DEFAULT_LOG_CONTEXT for this parameter is recommended
errorCodea code associated with this message
messagea brief one liner associated with this message
detailsa detailed multi-line text associated with this message
void GCF::Log::debug ( const QString &  context,
const QString &  message,
const QString &  details = QString() 
)

Logs a debug message into the current branch

Parameters
contexta string representing the context of the message. Use of GCF_DEFAULT_LOG_CONTEXT for this parameter is recommended
messagea brief one liner associated with this message
detailsa detailed multi-line text associated with this message
void GCF::Log::debug ( const QString &  context,
const QByteArray &  errorCode,
const QString &  message,
const QString &  details 
)

Logs a warning message into the current branch

Parameters
contexta string representing the context of the message. Use of GCF_DEFAULT_LOG_CONTEXT for this parameter is recommended
errorCodea code associated with this message
messagea brief one liner associated with this message
detailsa detailed multi-line text associated with this message
void GCF::Log::info ( const QString &  context,
const QString &  message,
const QString &  details = QString() 
)

Logs a information message into the current branch

Parameters
contexta string representing the context of the message. Use of GCF_DEFAULT_LOG_CONTEXT for this parameter is recommended
messagea brief one liner associated with this message
detailsa detailed multi-line text associated with this message
void GCF::Log::info ( const QString &  context,
const QByteArray &  errorCode,
const QString &  message,
const QString &  details 
)

Logs a information message into the current branch

Parameters
contexta string representing the context of the message. Use of GCF_DEFAULT_LOG_CONTEXT for this parameter is recommended
errorCodea code associated with this message
messagea brief one liner associated with this message
detailsa detailed multi-line text associated with this message
QList< GCF::LogMessage * > GCF::Log::logMessages ( ) const
Returns
list of top-level log messages and branches.
QString GCF::Log::toString ( ) const
Returns
a string representation of the log
void GCF::Log::copyToClipboard ( )

Requests the handler to copy the string representation of this log to the clipboard.

Note
Actual copy of log-messages to clipboard happens only if the handler supports it.
void GCF::Log::copyToSupport ( )

Requests the handler to submit the string representation of this log support (via email or otherwise).

Note
Actual submit of log-messages to support happens only if the handler supports it.
void GCF::Log::handleLogMessage ( GCF::LogMessage msg)
virtual

GCF::Log would call this function of the handler with the reported message so that the handler can log it appropriately.

Implements GCF::LogMessageHandlerInterface.

void GCF::Log::print ( GCF::LogMessage msg,
QTextStream &  ts 
)
virtual

GCF::Log would call this function of the handler with the reported message so that the handler can stream the log in appropriate print format to the text stream passed.

Implements GCF::LogMessageHandlerInterface.