The Logger class provides thread safe logging functionality to any Qt application. More...
#include <Logger.h>
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. | |
AbstractFormattingEngine * | formattingEngineReference (const QString &name) |
Returns a reference to the formatting engine specified by the name given. | |
AbstractFormattingEngine * | formattingEngineReferenceAt (int index) |
Returns a reference to the formatting engine at a specific position. | |
AbstractFormattingEngine * | formattingEngineReferenceFromExtension (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. | |
AbstractLoggerEngine * | loggerEngineReference (const QString &engine_name) |
Returns a reference to the logger known by the specified name. | |
AbstractLoggerEngine * | loggerEngineReferenceAt (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. | |
AbstractLoggerEngine * | 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. | |
AbstractLoggerEngine * | newLoggerEngine (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. |
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.
The possible message contexts used by the logger.
Logger engines will use the AllMessageContexts context by default.
The possible message types supported by the logger.
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.
|
slot |
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
logger_engine | The engine to be deleted. |
delete_engine | Indicates if the engine must be deleted after it was detached. |
void Qtilities::Logging::Logger::finalize | ( | const QString & | configuration_file_name = QString() | ) |
Finalizes the engine.
This saves the current session configuration.
configuration_file_name | The 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. |
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.
file_extension | See Qtilities::Logging::AbstractFormattingEngine::fileExtension() for the expected format. |
void Qtilities::Logging::Logger::initialize | ( | const QString & | configuration_file_name = QString() | ) |
Initializes the logger.
configuration_file_name | The 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. |
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.
|
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:
engine_name | The name of the engine to log to. If empty the message will be logged to all engines. |
message_type | The type of message. |
message | The message. |
msg1 | More parameters which can be passed to the logger. |
|
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.
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.
engine | The of the engine. This name can be used to reference the engine at a later stage. |
file_name | The name of the file to which logging must be done. If no engine name is provided the function will return false. |
formatting_engine | The 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. |
|
signal |
Signal which is emitted when a new priority message was logged.
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.
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.
bool Qtilities::Logging::Logger::setPriorityFormattingEngine | ( | const QString & | name | ) |
Function to change the formatting engine used for priority messages.
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().
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é
|