All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Types | Public Slots | Signals | Public Member Functions
Qtilities::Logging::Logger Class Reference

The Logger class provides thread safe logging functionality to any Qt application. More...

#include <Logger.h>

List of all members.

Public Types

enum  EngineChangeIndication { EngineAdded, EngineRemoved }
 Indication used to indicate if an engine was added or removed to/from the logger. More...
enum  MessageContext {
  NoMessageContext = 0, SystemWideMessages = 1, EngineSpecificMessages = 2, PriorityMessages = 4,
  AllMessageContexts = SystemWideMessages | EngineSpecificMessages | PriorityMessages
}
 The possible message contexts used by the logger. More...
enum  MessageType {
  None = 1 << 0, Info = 1 << 1, Warning = 1 << 2, Error = 1 << 3,
  Fatal = 1 << 4, Debug = 1 << 5, Trace = 1 << 6, AllLogLevels = Info | Warning | Error | Fatal | Debug | Trace
}
 The possible message types supported by the logger. More...

Public Slots

void clear ()
 Delete all logger engines.
void logMessage (const QString &engine_name, MessageType message_type, const QVariant &message, const QVariant &msg1=QVariant(), const QVariant &msg2=QVariant(), const QVariant &msg3=QVariant(), const QVariant &msg4=QVariant(), const QVariant &msg5=QVariant(), const QVariant &msg6=QVariant(), const QVariant &msg7=QVariant(), const QVariant &msg8=QVariant(), const QVariant &msg9=QVariant())
 Function to log a message.
void logPriorityMessage (const QString &engine_name, MessageType message_type, const QVariant &message, const QVariant &msg1=QVariant(), const QVariant &msg2=QVariant(), const QVariant &msg3=QVariant(), const QVariant &msg4=QVariant(), const QVariant &msg5=QVariant(), const QVariant &msg6=QVariant(), const QVariant &msg7=QVariant(), const QVariant &msg8=QVariant(), const QVariant &msg9=QVariant())
 Function to log a priority message.

Signals

void loggerEngineCountChanged (AbstractLoggerEngine *engine, Logger::EngineChangeIndication change_indication)
 Indicates that the number of logger engines changed.
void newMessage (const QString &engine_name, Logger::MessageType message_type, Logger::MessageContextFlags message_context, const QList< QVariant > &message_contents)
 Signal which is emitted when a new message was logged. The logger connects all logger engines to this signal.
void newPriorityMessage (Logger::MessageType message_type, const QString &formatted_message)
 Signal which is emitted when a new priority message was logged.

Public Member Functions

QStringList allLogLevelStrings () const
 Function which returns all available log level strings.
QStringList allMessageContextStrings () const
 Function which returns all available message contexts in a QStringList.
int attachedFormattingEngineCount () const
 Provides the number of attached formatting engines.
int attachedLoggerEngineCount () const
 Provides the number of attached logger engines.
QStringList attachedLoggerEngineNames () const
 Provides a QStringList with the names of all attached logger engines.
bool attachLoggerEngine (AbstractLoggerEngine *new_logger_engine, bool initialize_engine=true)
 Attaches the new logger engine. By default the new engine will be intialized by this function. If you want to initialize the engine manually, set the initialize_engine paramater to false.
QStringList availableFormattingEnginesInFactory () const
 Returns the names of all available formatting engines.
QStringList availableLoggerEnginesInFactory () const
 Function used to get a QStringList with the tags of all available logger engines.
bool consoleEngineActive () const
 Convenience function to check if the ConsoleEngine is active.
QString defaultFormattingEngine () const
 Returns the name of the default formatting engine.
void deleteAllLoggerEngines ()
 Deletes all logger engines, thus deactivate them.
void deleteEngine (const QString &engine_name)
 Deletes the specified engine.
bool detachLoggerEngine (AbstractLoggerEngine *logger_engine, bool delete_engine=true)
 Detaches the logger engine specified.
void disableAllLoggerEngines ()
 Disable all logger engines, thus deactivate them.
void disableEngine (const QString engine_name)
 Disables the specified backengineed.
void enableAllLoggerEngines ()
 Enable all logger engines, thus activate them.
void enableEngine (const QString &engine_name)
 Enable the specified engine.
void finalize (const QString &configuration_file_name=QString())
 Finalizes the engine.
AbstractFormattingEngineformattingEngineReference (const QString &name)
 Returns a reference to the formatting engine specified by the name given.
AbstractFormattingEngineformattingEngineReferenceAt (int index)
 Returns a reference to the formatting engine at a specific position.
AbstractFormattingEngineformattingEngineReferenceFromExtension (const QString &file_extension)
 Returns a reference to the formatting engine which provides the given file extension.
Logger::MessageType globalLogLevel () const
 Returns the current global log level.
void initialize (const QString &configuration_file_name=QString())
 Initializes the logger.
void installAsQtMessageHandler (bool update_stored_settings=true)
 Installs the logger as the Qt Message Handler.
bool isQtMessageHandler () const
 Returns true if the logger is the Qt Message Handler.
bool loadSessionConfig (QString file_name=QString())
 Loads the session config from a previous session.
AbstractLoggerEngineloggerEngineReference (const QString &engine_name)
 Returns a reference to the logger known by the specified name.
AbstractLoggerEngineloggerEngineReferenceAt (int index)
 Returns a reference to the logger engine at a specific position.
bool loggerSettingsEnabled () const
 Gets if the saving of settings by the logger is enabled.
QString logLevelToString (Logger::MessageType log_level) const
 Function which returns a string associated with a log level.
QString messageContextsToString (Logger::MessageContextFlags message_contexts) const
 Function which returns a string associated with set of message contexts.
AbstractLoggerEnginenewFileEngine (const QString &engine_name, const QString &file_name, const QString &formatting_engine=QString())
 Convenience function to create a new instance of a file engine.
AbstractLoggerEnginenewLoggerEngine (QString engine_tag, AbstractFormattingEngine *formatting_engine=0)
 Creates a new logger with the parameters specified.
bool qtMsgEngineActive () const
 Convenience function to check if the QtMsgEngine is active.
void readSettings ()
 Reads the current logging paramaters stored in QSettings.
void registerLoggerEngineFactory (const QString &tag, LoggerFactoryInterface< AbstractLoggerEngine > *factory_iface)
 Register a new logger engine factory.
bool rememberSessionConfig () const
 Returns true if the logger is configured to save the current logging engine configuration when the application exits, and load remember it (load it) the next time the appplication starts.
bool saveSessionConfig (QString file_name=QString(), Qtilities::ExportVersion version=Qtilities::Qtilities_Latest) const
 Save the current config to a file.
void setGlobalLogLevel (Logger::MessageType new_log_level)
 Sets the global log level. All messages are filtered by the logger according to the global log level before being sent to any logger engines.
void setIsQtMessageHandler (bool toggle)
 Toggles the logger as the Qt Message Handler.
void setLoggerSessionConfigPath (const QString path)
 Sets the session config path to be used by the logger.
void setLoggerSettingsEnabled (bool is_enabled)
 Enables/disables the saving of settings by the logger.
bool setPriorityFormattingEngine (const QString &name)
 Function to change the formatting engine used for priority messages.
void setPriorityFormattingEngine (AbstractFormattingEngine *engine)
 Function to change the formatting engine used for priority messages.
void setRememberSessionConfig (bool remember)
 Tell the logger to save the current logging engine configuration when the application exits, and load remember it (load it) the next time the appplication starts.
Logger::MessageType stringToLogLevel (const QString &log_level_string) const
 Function which returns the log level associated with an input string.
Logger::MessageContextFlags stringToMessageContexts (const QString &message_contexts_string) const
 Function which returns the message contexts associated with an input string.
void toggleConsoleEngine (bool toggle)
 Convenience function to enable a console engine.
void toggleQtMsgEngine (bool toggle)
 Convenience function to enable a Qt Message engine which pipes messages through to the Qt Debugging System.
void uninstallAsQtMessageHandler ()
 Uninstalls the logger as the Qt Message Handler.
void writeSettings () const
 Stores the logging parameters using QSettings.

Detailed Description

The Logger class provides thread safe logging functionality to any Qt application.

See the Logging article for more information on how to use the logger.


Member Enumeration Documentation

Indication used to indicate if an engine was added or removed to/from the logger.

Enumerator:
EngineAdded 

Engine was added to the logger.

EngineRemoved 

Engine was removed from the logger.

The possible message contexts used by the logger.

Logger engines will use the AllMessageContexts context by default.

Enumerator:
NoMessageContext 

No messages are accepted.

SystemWideMessages 

All system wide messages logged through the normal log marcos, for example LOG_INFO. Thus messages logged to all logger engines.

EngineSpecificMessages 

Messages logged to specific engines through the engine specific marcos, for example LOG_INFO_E.

PriorityMessages 

Messages logged to as priority messages through the priority marcos, for example LOG_INFO_P.

AllMessageContexts 

Represents all message contexts.

The possible message types supported by the logger.

See also:
setGlobalLogLevel(), globalLogLevel()
Enumerator:
None 

No messages will be logged when using this messages type.

Info 

An information message.

Warning 

A warning message.

Error 

An error message.

Fatal 

A fatal message.

Debug 

A debug message.

Note:
Trace messages are not part of release mode builds.
Trace 

A trace message.

Note:
Trace messages are not part of release mode builds.
AllLogLevels 

Represents all message types.


Member Function Documentation

QStringList Qtilities::Logging::Logger::availableFormattingEnginesInFactory ( ) const

Returns the names of all available formatting engines.

The Logger provided a set of ready to use formatting engines and this function provides the names which can be used to access these engines.

Note that the engines are registered in the logger during initialization, thus you must call initialize() before this function will return anything meaningfull.

See also:
initialize(), LOG_INITIALIZE
void Qtilities::Logging::Logger::clear ( )
slot

Delete all logger engines.

Note that this does not include the Qt Message Logger or Console Logging engines.

bool Qtilities::Logging::Logger::consoleEngineActive ( ) const

Convenience function to check if the ConsoleEngine is active.

This function was added in Qtilities v1.3.

bool Qtilities::Logging::Logger::detachLoggerEngine ( AbstractLoggerEngine logger_engine,
bool  delete_engine = true 
)

Detaches the logger engine specified.

detachLoggerEngine

Parameters:
logger_engineThe engine to be deleted.
delete_engineIndicates if the engine must be deleted after it was detached.
Returns:
True when successfull, false otherwise.
void Qtilities::Logging::Logger::finalize ( const QString &  configuration_file_name = QString())

Finalizes the engine.

This saves the current session configuration.

Parameters:
configuration_file_nameThe file name containing the configuration which much be loaded during the loadSessionConfig() call inside initialize(). When empty, Qtilities::Logging::Constants::qti_def_PATH_LOGCONFIG_FILE will be used.
See also:
LOG_FINALIZE, initialize()
Qtilities::Logging::AbstractFormattingEngine * Qtilities::Logging::Logger::formattingEngineReferenceFromExtension ( const QString &  file_extension)

Returns a reference to the formatting engine which provides the given file extension.

If multiple engines with the same file extension exists, the first one found will be used.

Parameters:
file_extensionSee Qtilities::Logging::AbstractFormattingEngine::fileExtension() for the expected format.
Returns:
Formatting engine if found, null otherwise.
void Qtilities::Logging::Logger::initialize ( const QString &  configuration_file_name = QString())

Initializes the logger.

Parameters:
configuration_file_nameThe file name containing the configuration which much be loaded during the loadSessionConfig() call inside initialize(). When empty, Qtilities::Logging::Constants::qti_def_PATH_LOGCONFIG_FILE will be used.
See also:
LOG_INITIALIZE, finalize()
bool Qtilities::Logging::Logger::loadSessionConfig ( QString  file_name = QString())

Loads the session config from a previous session.

If no file name is passed, the default session log file is used at QCoreApplication::applicationDirPath() + Qtilities::Logging::Constants::qti_def_PATH_SESSION + QDir::separator() + Qtilities::Logging::Constants::qti_def_PATH_LOGCONFIG_FILE. However in GUI applications the default path changes, see Qtilities::CoreGui::QtilitiesApplication::applicationSessionPath().

bool Qtilities::Logging::Logger::loggerSettingsEnabled ( ) const

Gets if the saving of settings by the logger is enabled.

Saving is enabled by default.

See also:
setLoggerSettingsEnabled(), Configuration settings storage in Qtilities
void Qtilities::Logging::Logger::logMessage ( const QString &  engine_name,
MessageType  message_type,
const QVariant &  message,
const QVariant &  msg1 = QVariant(),
const QVariant &  msg2 = QVariant(),
const QVariant &  msg3 = QVariant(),
const QVariant &  msg4 = QVariant(),
const QVariant &  msg5 = QVariant(),
const QVariant &  msg6 = QVariant(),
const QVariant &  msg7 = QVariant(),
const QVariant &  msg8 = QVariant(),
const QVariant &  msg9 = QVariant() 
)
slot

Function to log a message.

This function can be used when the log macros are not sufficient. It allows you to pass nine additional paramaters along with the engine name, message type and message itself.

You can write your own formatting engine to interpret these paramaters. This allows the creation of very powerfull and custom logging backends.

From the formatting engines included in Qtilities, the following ones support the additional parameters:

Parameters:
engine_nameThe name of the engine to log to. If empty the message will be logged to all engines.
message_typeThe type of message.
messageThe message.
msg1More parameters which can be passed to the logger.
See also:
LOG_DEBUG, LOG_ERROR, LOG_WARNING, LOG_INFO, LOG_TRACE, LOG_FATAL
void Qtilities::Logging::Logger::logPriorityMessage ( const QString &  engine_name,
MessageType  message_type,
const QVariant &  message,
const QVariant &  msg1 = QVariant(),
const QVariant &  msg2 = QVariant(),
const QVariant &  msg3 = QVariant(),
const QVariant &  msg4 = QVariant(),
const QVariant &  msg5 = QVariant(),
const QVariant &  msg6 = QVariant(),
const QVariant &  msg7 = QVariant(),
const QVariant &  msg8 = QVariant(),
const QVariant &  msg9 = QVariant() 
)
slot

Function to log a priority message.

A priority message is handled in the same way as a normal message logged with logMessage() except that it also emits the newPriorityMessage() signal. This allows selective messages to be emitted and displayed in a convenient place in an application where all messages should not necessarily be displayed. An example is the case where selective messages should be displayed in a status bar.

By default priority messages are unformatted and message is used.

See also:
LOG_DEBUG_P, LOG_ERROR_P, LOG_WARNING_P, LOG_INFO_P, LOG_TRACE_P, LOG_FATAL_P
Qtilities::Logging::AbstractLoggerEngine * Qtilities::Logging::Logger::newFileEngine ( const QString &  engine_name,
const QString &  file_name,
const QString &  formatting_engine = QString() 
)

Convenience function to create a new instance of a file engine.

Parameters:
engineThe of the engine. This name can be used to reference the engine at a later stage.
file_nameThe name of the file to which logging must be done. If no engine name is provided the function will return false.
formatting_engineThe name of the formatting engine which must be used to format messages in the engine. When empty the file extension of file_name is used to determine the formatting engine used for the file by checking the Qtilities::Logging::AbstractFormattingEngine::fileExtension() functions of all the available formatting engines. If the file extension does not match any of the available file extensions, the Qtilities::Logging::FormattingEngine_Default formatting engine is used.
Returns:
The constructed logger engine if successfull, null otherwise.
void Qtilities::Logging::Logger::newPriorityMessage ( Logger::MessageType  message_type,
const QString &  formatted_message 
)
signal

Signal which is emitted when a new priority message was logged.

See also:
logPriorityMessage();
bool Qtilities::Logging::Logger::qtMsgEngineActive ( ) const

Convenience function to check if the QtMsgEngine is active.

This function was added in Qtilities v1.3.

void Qtilities::Logging::Logger::readSettings ( )

Reads the current logging paramaters stored in QSettings.

For more information see Configuration settings storage in Qtilities.

bool Qtilities::Logging::Logger::rememberSessionConfig ( ) const

Returns true if the logger is configured to save the current logging engine configuration when the application exits, and load remember it (load it) the next time the appplication starts.

See also:
setRememberSessionConfig()
bool Qtilities::Logging::Logger::saveSessionConfig ( QString  file_name = QString(),
Qtilities::ExportVersion  version = Qtilities::Qtilities_Latest 
) const

Save the current config to a file.

If no file name is passed, the default session log file in GUI applications is used at QCoreApplication::applicationDirPath() + Qtilities::Logging::Constants::qti_def_PATH_SESSION + QDir::separator() + Qtilities::Logging::Constants::qti_def_PATH_LOGCONFIG_FILE. However in GUI applications the default path changes, see Qtilities::CoreGui::QtilitiesApplication::applicationSessionPath().

This function is automatically called in:

void Qtilities::Logging::Logger::setLoggerSessionConfigPath ( const QString  path)

Sets the session config path to be used by the logger.

The logger uses this path to save internal settings, and to save its logger configurations.

For more information about internal settings see Configuration settings storage in Qtilities and loggerSettingsEnabled().

void Qtilities::Logging::Logger::setLoggerSettingsEnabled ( bool  is_enabled)

Enables/disables the saving of settings by the logger.

Saving is enabled by default.

See also:
loggerSettingsEnabled(), Configuration settings storage in Qtilities
bool Qtilities::Logging::Logger::setPriorityFormattingEngine ( const QString &  name)

Function to change the formatting engine used for priority messages.

Returns:
True if successfull, thus a formatting engine called name could be found. False otherwise.
void Qtilities::Logging::Logger::setRememberSessionConfig ( bool  remember)

Tell the logger to save the current logging engine configuration when the application exits, and load remember it (load it) the next time the appplication starts.

To keep logger engine configurations between sessions, just call Log->setRememberSessionConfig(true) before LOG_INITIALIZE().

See also:
rememberSessionConfig()
void Qtilities::Logging::Logger::toggleConsoleEngine ( bool  toggle)

Convenience function to enable a console engine.

Only one console engine can be created. This engine can be enabled/disabled using this function.

void Qtilities::Logging::Logger::toggleQtMsgEngine ( bool  toggle)

Convenience function to enable a Qt Message engine which pipes messages through to the Qt Debugging System.

Only one qt message engine can be created. This engine can be enabled/disabled using this function.

void Qtilities::Logging::Logger::writeSettings ( ) const

Stores the logging parameters using QSettings.

For more information see Configuration settings storage in Qtilities and loggerSettingsEnabled()



Qtilities : Reference Documentation Back to top Copyright © 2009-2013, Jaco Naudé