CTL
0.6.1
Computed Tomography Library
|
The MessageHandler class provides a means to control the message output of the CTL and allows saving log files. More...
#include <messagehandler.h>
Public Slots | |
void | messageFromSignal (QString msg) |
Signals | |
void | newLogEntry () const |
void | messagePrinted () const |
Public Member Functions | |
MessageHandler (const MessageHandler &)=delete | |
MessageHandler (MessageHandler &&)=delete | |
MessageHandler & | operator= (const MessageHandler &)=delete |
MessageHandler & | operator= (MessageHandler &&)=delete |
const QStringList & | log () const |
QString | lastMessage () const |
void | blacklistAll (bool blacklist=true) |
template<class ... QString> | |
void | blacklistClassOrFunction (const QString &... names) |
template<class ... QString> | |
void | blacklistFile (const QString &... names) |
void | blacklistMessageType (QtMsgType type) |
void | clearAllBlacklists () |
void | clearAllWhitelists () |
void | enforceLoggingOfBlacklistMsg (bool enabled=true) |
void | setLogFileName (const QString &fileName) |
void | squelch (bool enabled=true) |
void | setQuiet (bool enabled=true) |
void | toggleDateTag (bool show) |
void | toggleMessageOriginTag (bool show) |
void | toggleTimeTag (bool show) |
void | toggleTypeTag (bool show) |
void | toggleAllTags (bool show) |
template<class ... QString> | |
void | whitelistClassOrFunction (const QString &... names) |
template<class ... QString> | |
void | whitelistFile (const QString &... names) |
bool | writeLogFile () const |
bool | writeLogFileAndClear () |
void | processMessage (QtMsgType type, const QMessageLogContext &context, const QString &msg) |
Static Public Member Functions | |
static MessageHandler & | instance () |
static void | qInstaller (QtMsgType type, const QMessageLogContext &context, const QString &msg) |
The MessageHandler class provides a means to control the message output of the CTL and allows saving log files.
To use the MessageHandler in an application, install it using:
The output can be configured using black- and whitelisting. For more details, see the corresponding methods:
To change settings, get the MessageHandler instance and call the corresponding methods on that object. Example:
Writing a log file can be initiated by writeLogFile(). The log file name can be set through setLogFileName().
void CTL::MessageHandler::blacklistAll | ( | bool | blacklist = true | ) |
Blacklists all messages. Can be used in combination with whitelisting to filter individual messages.
Note that the effect of this cannot be reverted using clearAllBlacklists(), as no actual blacklist entries are created. Instead, call blacklistAll(false) to disable full blacklisting.
Example: suppress all message output except for messages from the CarmGantry class
void CTL::MessageHandler::blacklistClassOrFunction | ( | const QString &... | names | ) |
Adds all passed class and function names to the blacklist. You can pass an arbitrary number of names. There is no differentiation between class and function names, ie. any class or function name that matches a string passed to names will be blacklisted. Note that blacklist strings do not need to be complete; partial matches already lead to blacklisting of all corresponding entries.
Example:
Blacklisted messages will not be printed as console output. However, you can enforce logging of these messages to the log file by enabling enforceLoggingOfBlacklistMsg(), if necessary.
void CTL::MessageHandler::blacklistFile | ( | const QString &... | names | ) |
Adds all passed file names to the blacklist. You can pass an arbitrary number of names. Note that blacklist strings do not need to be complete; partial matches already lead to blacklisting of all corresponding entries.
Example:
Blacklisted messages will not be printed as console output. However, you can enforce logging of these messages to the log file by enabling enforceLoggingOfBlacklistMsg(), if necessary.
void CTL::MessageHandler::blacklistMessageType | ( | QtMsgType | type | ) |
Blacklists all messages of type type.
The following types are available:
void CTL::MessageHandler::clearAllBlacklists | ( | ) |
Removes all entries from the blacklists.
Note that this does not revert the effect of blacklistAll().
void CTL::MessageHandler::clearAllWhitelists | ( | ) |
Removes all entries from the whitelists.
void CTL::MessageHandler::enforceLoggingOfBlacklistMsg | ( | bool | enabled = true | ) |
Enforces that messages from blacklisted origins will still be added to the log. Thus, they will be written to the log file and can also be retrieved using log() and lastMessage(), if required.
|
static |
Returns a reference to the singleton instance.
Use this method whenever you want to interact with the message handler.
QString CTL::MessageHandler::lastMessage | ( | ) | const |
Returns the last message as a QString.
Note that if logging of blacklisted messages is enabled (see enforceLoggingOfBlacklistMsg()), this can also return a blacklisted message (ie. a message that has not been printed to console output).
const QStringList & CTL::MessageHandler::log | ( | ) | const |
Returns the entire log as a QStringList (each list entry refers to a single message).
Note that if logging of blacklisted messages is enabled (see enforceLoggingOfBlacklistMsg()), this also contains all blacklisted messages.
|
slot |
Slot that can be used to connect signals from external classes that emit a QString to process it as a QtInfoMsg.
|
static |
Function that needs to be passed to qInstallMessageHandler() in order to let this message handler taking care of the Qt message streams.
Usage:
void CTL::MessageHandler::setLogFileName | ( | const QString & | fileName | ) |
Sets the file name used for saving the log file to fileName.
Note that the file needs to be writable in order to successfully create the log file.
void CTL::MessageHandler::setQuiet | ( | bool | enabled = true | ) |
Sets use of quiet mode to enabled. In quiet mode, no messages are printed to console output.
void CTL::MessageHandler::squelch | ( | bool | enabled = true | ) |
Sets use of quiet mode to enabled. In quiet mode, no messages are printed to console output.
Same as setQuiet().
void CTL::MessageHandler::toggleAllTags | ( | bool | show | ) |
Sets the inclusion of all message tags into message strings to show.
void CTL::MessageHandler::toggleDateTag | ( | bool | show | ) |
Sets the inclusion of the date tag into message strings to show.
void CTL::MessageHandler::toggleMessageOriginTag | ( | bool | show | ) |
Sets the inclusion of the message origin tag into message strings to show.
void CTL::MessageHandler::toggleTimeTag | ( | bool | show | ) |
Sets the inclusion of the time tag into message strings to show.
void CTL::MessageHandler::toggleTypeTag | ( | bool | show | ) |
Sets the inclusion of the type tag into message strings to show.
void CTL::MessageHandler::whitelistClassOrFunction | ( | const QString &... | names | ) |
Adds all passed class and function names to the whitelist. You can pass an arbitrary number of names. There is no differentiation between class and function names, ie. any class or function name that matches a string passed to names will be whitelisted. Note that whitelist strings do not need to be complete; partial matches already lead to whitelisting of all corresponding entries.
Whitelisted messages ignore all blacklist entries, meaning they will always be printed as console output.
Whitelisting is only meaningful in combination with previous blacklisting.
Example: suppress all message output except for messages from the CarmGantry class
Example 2: suppress all message output except for messages from any "Gantry" class
void CTL::MessageHandler::whitelistFile | ( | const QString &... | names | ) |
Adds all passed file names to the whitelist. You can pass an arbitrary number of names. Note that whitelist strings do not need to be complete; partial matches already lead to whitelisting of all corresponding entries.
Whitelisted messages ignore all blacklist entries, meaning they will always be printed as console output.
Whitelisting is only meaningful in combination with previous blacklisting.
Example: suppress all message output except for messages from the trajectories.cpp file
bool CTL::MessageHandler::writeLogFile | ( | ) | const |
Initiates writing of the log file to the file name specified by setLogFileName().
Returns true
on a successful write.
bool CTL::MessageHandler::writeLogFileAndClear | ( | ) |
Same as writeLogFile() but also clears the current log after a successful write.