WARNING: USE THIS SOFTWARE AT YOUR OWN RISK! THIS IS EXPERIMENTAL SOFTWARE NOT INTENDED FOR PRODUCTION USE! Zuble is currently an early stage prototype. As such Zuble is minimally tested and inherently unstable. It is provided for experimental, development, and demonstration purposes only. | Zuble QML Types | Zuble C++ Classes | Zuble Overview |
Zuble
0.1
Zuble Framework C++/QML extension API
|
The Zuble Log Manager is a singleton object that controls logging in Zuble applications. More...
#include <ZblLogManager.h>
Public Types | |
enum | logFields { LogFieldRecordNum = 0, LogFieldCategory = 1, LogFieldSource = 2, LogFieldMessage = 3, LogFieldFunction = 4, LogFieldLine = 5, LogFieldFile = 6, LogFieldMark = 7 } |
Roles for the log record data model. More... | |
enum | ruleFields { RuleCategory = 0, RuleRegistered = 1, RuleSaved = 2, RuleEnabled = 3, RuleWarning = 4, RuleCritical = 5, RuleDebug = 6 } |
Roles for the logging rules data model. More... | |
Public Slots | |
bool | registerLogCategory (const QString logCategory) |
Adds the specified log category to the registered log category list. More... | |
void | onLogProfileModified (const QString &path) |
Responds to changes to the current log settings by replacing the log profile with the current log settings. More... | |
void | onZubleSettingsModified (const QString &path) |
Responds to changes in the Zuble application settingsby updating log manager's internal state. @ param path. More... | |
void | onLogWorkerOutputParametersUpdated (QVariant logParams) |
Synchronizes log manager and log worker output parameters. More... | |
void | onSettingsBundleAvailable (QString bundleId) |
Responds to newly loaded settings bundles. More... | |
bool | loadFilterRules (const QString &logProfileBundleID) |
Loades the log filter rules from the specified log profile into the log rule model. More... | |
void | onRuleModelModified (int dataRole, int rowNumber) |
Responds to changes in the rule model by updating Qt's internal rule model and the current log settings file. More... | |
void | saveFilterRules () |
Saves the current state of the logging rules data model to the current log profile. More... | |
void | populateRegisteredRules () |
Appends all log categories that have so far been registered with a call to ZblLogManager::registerLogCategory() to the logging rules data model. More... | |
bool | appendRuleModelCategory (const QString &logCategory) |
Adds a new category to the rule model. If the category already exists in the rule model the request to add is ignored. More... | |
Public Member Functions | |
ZblLogManager (QObject *parent=0) | |
virtual | ~ZblLogManager () |
Q_INVOKABLE QObject * | getLogBuffer () |
Obtain the log buffer data model. More... | |
Q_INVOKABLE int | getLogBufferRoleCount () |
Obtain the number of roles in the log buffer data model. More... | |
Q_INVOKABLE QObject * | getLogRules () |
Obtain the logging rules data model. More... | |
virtual void | timerEvent (QTimerEvent *event) |
Timer is used to flush excess log records from the log record buffer. More... | |
ZTableModel * | createLogBufferModel (QObject *parent=NULL) |
Creates a new log record data model by appending the appropriate data rules. The caller assumes ownership of the data model. More... | |
Static Public Member Functions | |
static ZblLogManager & | zInit (QObject *parent) |
Construct, initialize and obtain a reference to Zuble's log manager object. More... | |
static ZblLogManager & | zInstance () |
Obtain a reference to Zuble's log manager object. More... | |
Protected Member Functions | |
ZBL_DECLARE_LOGGED_OBJECT QString | getQtLogRule (const QString &category, const QString &level, bool enabled) |
Returns a Qt logging rule string for the given log category and level. More... | |
QString | getQtLogRulesForRow (int rowNumber) |
Returns a Qt logging rule string for all logging levels for the specified row (log category) in the logging rules data model. More... | |
void | setQtLogRulesFromModel () |
Sets Qt's internal logging rules from data contained in log manager's logging rules model. More... | |
bool | createRuleModel () |
Creates the log manager's log rules data model and initializes associated variables used to optimize performance of adding rules to the model, then connects log manager to appropriate rule model signals. This method should only be called once. More... | |
bool | isCommandLineLogging () |
Returns true if -zl option is passed in on command line. More... | |
bool | startLogThread () |
Starts log manager's background thread. More... | |
void | stopLogThread () |
Stops log manager's background thread. More... | |
bool | populateMetaRules () |
Appends all log categories defined in the Zuble application's zblconfig.xml configuration file to the logging rules data model. More... | |
void | setApplicationObject (ZApplication *appObject) |
Connects the log manager to appropriate Zuble core plugin signals and attempts to load the current log profile if one is available. This method should be called only once. More... | |
void | updateApplicationSettings () |
void | updateLogProfileSettings () |
Loads a new copy of the log profile settings from the settings file. More... | |
bool | loadCurrentLogProfile () |
Replaces the current log settings with those from the specified file. More... | |
void | setLogOutputParameters () |
Gathers the application and log profile settings that affect log output and synchronizes those parameters with the ZblLogWorker object. More... | |
Static Protected Member Functions | |
static QString | createTemporaryLogProfile (const QString &nameTemplate, bool remove=false) |
Creates an empty file with a unique file name in the log profile directory. More... | |
static QString | getLogSettingsMetadata () |
Returns an xml data structure that defines the zuble application's log settings. More... | |
static LogFileFormat | fileFormatFromString (const QString &logFileFormat) |
Static Protected Attributes | |
static const QString | m_currentLogSettingsBundleId = "current-log-profile" |
The bundle ID for the current logging profile = "current-log-profile". More... | |
static const QString | m_zubleSettingsBundleId = "default" |
The bundle ID for the zuble application settings = "default". More... | |
static const QString | m_defaultOutputFilePath = "" |
TBD: currently unused! More... | |
Static Private Member Functions | |
static void | zMessageHandler (QtMsgType msgType, const QMessageLogContext &logCtx, const QString &text) |
Zuble's Qt message handler. More... | |
Private Attributes | |
ZblLogParams | m_logParam |
Current Zuble logging parameters. More... | |
int | m_timerID |
ID for the log manager's event timer. More... | |
ZTableModel * | m_logBuffer |
Zuble's log buffer provides a viewable record of recent log activity. More... | |
ZRoleNames | m_bufferRoles |
A hash of log buffer column numbers to column field names. More... | |
QThread | m_logThread |
A background thread to handle logging rules and log record output. More... | |
ZblLogWorker * | m_logWorker |
A background thread worker object to handle logging rules and log record output. More... | |
ZTableModel * | m_logRules |
A data model containing the current logging rules in effect for each known log category. More... | |
ZDataRow | m_modelCategoryRow |
A data row to use as a template for constructing role rows. More... | |
ZDataRow | m_modelBooleanRow |
A data row to use as a template for constructing role rows. More... | |
ZRoleRow | m_modelRoleRow |
A role row to use as a template for adding logging rules to the rule model. More... | |
ZSettings * | m_logSettings |
A ZSettings object to track the application settings for changes that control Zuble logging. More... | |
ZSettings * | m_profileSettings |
A ZSettings object to track the current log profile for changes to the profile settings. More... | |
bool | m_syncProfiles |
true if all application instances update the same log profile, false if each instance updates a separate copy of the log profile. More... | |
bool | m_loadingProfile |
true when log manager is currently loading a log profile, false otherwise More... | |
QString | m_LogSource |
String inserted into the "source" field of log records. More... | |
QtMessageHandler | m_originalMsgHandler |
Pointer to the original (non-Zuble) message handler, or nullptr if Zuble logging has not yet been enabled for the first time. More... | |
Static Private Attributes | |
static ZblLogManager * | m_zLog = nullptr |
The one and only ZblLogManager object in this process. More... | |
static const QString | m_logFilterRulesKey = "log-filter-rules" |
The log filter rules key = "log-filter-rules". More... | |
static int | m_maxBufferSize = 1000 |
The number of logging records the circular log buffer will attempt to hold. More... | |
static const QString | m_profileMetadata |
Log profile metadata defines logger settings that are stored in a log profile. More... | |
static const int | m_logBufRoleCount = 7 |
The number of roles contained in a log file record. More... | |
Friends | |
class | Zblcore |
class | ZblLogCategory |
class | ZblLogWorker |
The Zuble Log Manager is a singleton object that controls logging in Zuble applications.
Log Manager maintains a list of log categories that can be enumerated and controlled from QML/javascript programs. The Qt/QML default message handler is replaced with log manager's own internal message handler.
Log Manager converts log messages received from Qt into log records. A log record is an array of QVariant objects that represents a row in a data model. The log manager optionally maintains a circular log buffer that contains a list of the most recent log records.
Use of the log message handler, log buffer and log file are optional. The log manager is turned off by default and must be enabled by one of the following methods:
methods TBD
Definition at line 70 of file ZblLogManager.h.
Roles for the log record data model.
Enumerator | |
---|---|
LogFieldRecordNum | |
LogFieldCategory | |
LogFieldSource | |
LogFieldMessage | |
LogFieldFunction | |
LogFieldLine | |
LogFieldFile | |
LogFieldMark |
Definition at line 89 of file ZblLogManager.h.
Roles for the logging rules data model.
Enumerator | |
---|---|
RuleCategory | |
RuleRegistered | |
RuleSaved | |
RuleEnabled | |
RuleWarning | |
RuleCritical | |
RuleDebug |
Definition at line 105 of file ZblLogManager.h.
|
explicit |
Definition at line 182 of file ZblLogManager.cpp.
Referenced by zInit().
|
virtual |
Definition at line 204 of file ZblLogManager.cpp.
|
slot |
Adds a new category to the rule model. If the category already exists in the rule model the request to add is ignored.
logCategory | name of the log category to add. |
Definition at line 1019 of file ZblLogManager.cpp.
Referenced by populateRegisteredRules(), and Zbl::ZblLogCategory::registerCategory().
ZTableModel * Zbl::ZblLogManager::createLogBufferModel | ( | QObject * | parent = NULL | ) |
Creates a new log record data model by appending the appropriate data rules. The caller assumes ownership of the data model.
parent | The object that will become the parent of the data model or null (default) if ZblLogManager object should be the parent. |
Definition at line 704 of file ZblLogManager.cpp.
Referenced by zInit().
|
protected |
Creates the log manager's log rules data model and initializes associated variables used to optimize performance of adding rules to the model, then connects log manager to appropriate rule model signals. This method should only be called once.
Definition at line 967 of file ZblLogManager.cpp.
Referenced by zInit().
|
staticprotected |
Creates an empty file with a unique file name in the log profile directory.
Creates the log profile directory if it doesn't already exist. QTemporaryFile is used to create the file.
nameTemplate | A name template to use when building the temporary file name. |
remove | Removes the temporary file after creation when true. Default is false. |
Definition at line 463 of file ZblLogManager.cpp.
Referenced by loadCurrentLogProfile().
|
staticprotected |
Definition at line 1103 of file ZblLogManager.cpp.
Referenced by setLogOutputParameters().
QObject * Zbl::ZblLogManager::getLogBuffer | ( | ) |
Obtain the log buffer data model.
Definition at line 645 of file ZblLogManager.cpp.
Referenced by Zbl::ZblApp::getLogBuffer().
int Zbl::ZblLogManager::getLogBufferRoleCount | ( | ) |
Obtain the number of roles in the log buffer data model.
Definition at line 650 of file ZblLogManager.cpp.
QObject * Zbl::ZblLogManager::getLogRules | ( | ) |
Obtain the logging rules data model.
Modifying the data model will cause log manager to make corresponding modifications to Qt's internal logging data structures.
Definition at line 656 of file ZblLogManager.cpp.
Referenced by Zbl::ZblApp::getLogRules().
|
staticprotected |
Returns an xml data structure that defines the zuble application's log settings.
These settings control whether the Zuble log manager handles Qt log messages and what log profile should be used to initialize and update Zuble's log manager state. The XML metadata defines the settings themselves. The data for the settings is stored separately in JSON files.
Definition at line 372 of file ZblLogManager.cpp.
Referenced by loadCurrentLogProfile().
|
protected |
Returns a Qt logging rule string for the given log category and level.
category | The log category name for the rule string. WARNING: it must not contain dot (".")!<—Warning: that might be a lie! buwahahaha! |
level | The log level, one of either "warning", "critical", or "debug". |
enabled | true to return a rule string that enables the category/level, false to return a rule string that disables the category/level |
Definition at line 947 of file ZblLogManager.cpp.
Referenced by getQtLogRulesForRow().
|
protected |
Returns a Qt logging rule string for all logging levels for the specified row (log category) in the logging rules data model.
rowNumber | The row in the data model for which a logging rules string will be concatenated. Each row contains the rules for all levels of a single logging category. |
Definition at line 929 of file ZblLogManager.cpp.
Referenced by setQtLogRulesFromModel().
|
protected |
Returns true if -zl option is passed in on command line.
Definition at line 507 of file ZblLogManager.cpp.
|
protected |
Replaces the current log settings with those from the specified file.
logProfilePath | The path to the log profile to load |
Definition at line 400 of file ZblLogManager.cpp.
Referenced by onSettingsBundleAvailable(), onZubleSettingsModified(), and setApplicationObject().
|
slot |
Loades the log filter rules from the specified log profile into the log rule model.
logProfileBundleID | The bundle ID for the log profile |
Definition at line 888 of file ZblLogManager.cpp.
Referenced by loadCurrentLogProfile(), and zInit().
|
slot |
Responds to changes to the current log settings by replacing the log profile with the current log settings.
path |
Definition at line 773 of file ZblLogManager.cpp.
Referenced by updateLogProfileSettings().
|
slot |
Synchronizes log manager and log worker output parameters.
Log manager doesn't set it's internal log output parameters or enable its log message handler until log worker object has been set up to receive log records. Since these objects are in different threads we use the ZblLogWorker::outputParametersUpdated signal to ensure the log worker is ready to accept log output before switching to Zuble's log message handler.
enableLogging | |
logOutputDir | |
enableModel | |
enableFile | |
fileType |
Definition at line 821 of file ZblLogManager.cpp.
Referenced by zInit().
|
slot |
Responds to changes in the rule model by updating Qt's internal rule model and the current log settings file.
dataRole | |
rowNumber |
Definition at line 1044 of file ZblLogManager.cpp.
Referenced by createRuleModel().
|
slot |
Responds to newly loaded settings bundles.
bundleId | the settings bundle that was recently loaded |
Definition at line 314 of file ZblLogManager.cpp.
Referenced by setApplicationObject().
|
slot |
Responds to changes in the Zuble application settingsby updating log manager's internal state. @ param path.
Definition at line 848 of file ZblLogManager.cpp.
Referenced by updateApplicationSettings().
|
protected |
Appends all log categories defined in the Zuble application's zblconfig.xml configuration file to the logging rules data model.
TBD: this function currently an unimplemented stub. sry....
Definition at line 877 of file ZblLogManager.cpp.
|
slot |
Appends all log categories that have so far been registered with a call to ZblLogManager::registerLogCategory() to the logging rules data model.
Definition at line 1081 of file ZblLogManager.cpp.
Referenced by zInit().
|
slot |
Adds the specified log category to the registered log category list.
logCategory | the name of the log category to add. Duplicates are silently ignored |
Definition at line 674 of file ZblLogManager.cpp.
|
slot |
Saves the current state of the logging rules data model to the current log profile.
test
end test
Definition at line 1059 of file ZblLogManager.cpp.
Referenced by loadCurrentLogProfile(), onRuleModelModified(), and populateRegisteredRules().
|
protected |
Connects the log manager to appropriate Zuble core plugin signals and attempts to load the current log profile if one is available. This method should be called only once.
appObject | Zuble core plugin's ZApplication object. |
Definition at line 291 of file ZblLogManager.cpp.
|
protected |
Gathers the application and log profile settings that affect log output and synchronizes those parameters with the ZblLogWorker object.
Definition at line 781 of file ZblLogManager.cpp.
Referenced by onLogProfileModified(), onZubleSettingsModified(), and updateLogProfileSettings().
|
protected |
Sets Qt's internal logging rules from data contained in log manager's logging rules model.
Definition at line 953 of file ZblLogManager.cpp.
Referenced by loadFilterRules(), and onRuleModelModified().
|
protected |
Starts log manager's background thread.
Definition at line 738 of file ZblLogManager.cpp.
Referenced by zInit().
|
protected |
Stops log manager's background thread.
Definition at line 764 of file ZblLogManager.cpp.
Referenced by zMessageHandler(), and ~ZblLogManager().
|
virtual |
Timer is used to flush excess log records from the log record buffer.
event |
Definition at line 635 of file ZblLogManager.cpp.
|
protected |
Definition at line 334 of file ZblLogManager.cpp.
Referenced by onSettingsBundleAvailable(), and setApplicationObject().
|
protected |
Loads a new copy of the log profile settings from the settings file.
Definition at line 352 of file ZblLogManager.cpp.
Referenced by loadCurrentLogProfile().
|
static |
Construct, initialize and obtain a reference to Zuble's log manager object.
Definition at line 212 of file ZblLogManager.cpp.
|
static |
Obtain a reference to Zuble's log manager object.
Definition at line 570 of file ZblLogManager.cpp.
Referenced by Zbl::ZblApp::getLogBuffer(), and Zbl::ZblApp::getLogRules().
|
staticprivate |
Zuble's Qt message handler.
msgType | The type of message being sent. |
logCtx | Provides information about the message source. |
text | The message text |
Definition at line 581 of file ZblLogManager.cpp.
Referenced by isCommandLineLogging(), and onLogWorkerOutputParametersUpdated().
|
friend |
Definition at line 72 of file ZblLogManager.h.
|
friend |
Definition at line 73 of file ZblLogManager.h.
|
friend |
Definition at line 74 of file ZblLogManager.h.
Referenced by zInit().
|
private |
A hash of log buffer column numbers to column field names.
Definition at line 541 of file ZblLogManager.h.
|
staticprotected |
The bundle ID for the current logging profile = "current-log-profile".
This bundle ID is used by the log manager to save and restore the current state of the log manager settings. WARNING: this bundle ID is reserved for use by Zuble!
Definition at line 482 of file ZblLogManager.h.
Referenced by loadCurrentLogProfile(), onSettingsBundleAvailable(), saveFilterRules(), updateLogProfileSettings(), and zInit().
|
staticprotected |
TBD: currently unused!
Definition at line 496 of file ZblLogManager.h.
|
private |
true when log manager is currently loading a log profile, false otherwise
Definition at line 644 of file ZblLogManager.h.
Referenced by loadCurrentLogProfile().
|
private |
Zuble's log buffer provides a viewable record of recent log activity.
Definition at line 535 of file ZblLogManager.h.
Referenced by getLogBuffer(), timerEvent(), and zInit().
|
staticprivate |
The number of roles contained in a log file record.
Definition at line 628 of file ZblLogManager.h.
Referenced by createLogBufferModel(), and getLogBufferRoleCount().
|
staticprivate |
The log filter rules key = "log-filter-rules".
This key is used by log manager to store the logging category filter rules in log profiles.
Definition at line 587 of file ZblLogManager.h.
Referenced by loadCurrentLogProfile(), loadFilterRules(), and saveFilterRules().
|
private |
Current Zuble logging parameters.
Definition at line 515 of file ZblLogManager.h.
Referenced by onLogWorkerOutputParametersUpdated(), and setLogOutputParameters().
|
private |
A data model containing the current logging rules in effect for each known log category.
Definition at line 563 of file ZblLogManager.h.
Referenced by appendRuleModelCategory(), createRuleModel(), getLogRules(), getQtLogRulesForRow(), loadFilterRules(), onZubleSettingsModified(), populateRegisteredRules(), saveFilterRules(), and setQtLogRulesFromModel().
|
private |
A ZSettings object to track the application settings for changes that control Zuble logging.
Definition at line 595 of file ZblLogManager.h.
Referenced by loadCurrentLogProfile(), onZubleSettingsModified(), setLogOutputParameters(), updateApplicationSettings(), and ~ZblLogManager().
|
private |
String inserted into the "source" field of log records.
Definition at line 650 of file ZblLogManager.h.
Referenced by zInit().
|
private |
A background thread to handle logging rules and log record output.
Definition at line 548 of file ZblLogManager.h.
Referenced by startLogThread(), stopLogThread(), zInit(), and zMessageHandler().
|
private |
A background thread worker object to handle logging rules and log record output.
Definition at line 555 of file ZblLogManager.h.
Referenced by setLogOutputParameters(), zInit(), and zMessageHandler().
|
staticprivate |
The number of logging records the circular log buffer will attempt to hold.
The log buffer is periodically truncated to this size but may temporarily grow larger depending on logging frequency.
Definition at line 615 of file ZblLogManager.h.
Referenced by timerEvent().
|
private |
A data row to use as a template for constructing role rows.
Definition at line 573 of file ZblLogManager.h.
Referenced by createRuleModel().
|
private |
A data row to use as a template for constructing role rows.
Definition at line 568 of file ZblLogManager.h.
Referenced by appendRuleModelCategory(), and createRuleModel().
|
private |
A role row to use as a template for adding logging rules to the rule model.
Definition at line 579 of file ZblLogManager.h.
Referenced by appendRuleModelCategory(), and createRuleModel().
|
private |
Pointer to the original (non-Zuble) message handler, or nullptr if Zuble logging has not yet been enabled for the first time.
Definition at line 657 of file ZblLogManager.h.
|
staticprivate |
Log profile metadata defines logger settings that are stored in a log profile.
Definition at line 622 of file ZblLogManager.h.
Referenced by getLogSettingsMetadata().
|
private |
A ZSettings object to track the current log profile for changes to the profile settings.
Definition at line 603 of file ZblLogManager.h.
Referenced by loadCurrentLogProfile(), setLogOutputParameters(), and updateLogProfileSettings().
|
private |
true if all application instances update the same log profile, false if each instance updates a separate copy of the log profile.
This allows decoupling of the log settings for separate app instances.
Definition at line 638 of file ZblLogManager.h.
Referenced by loadCurrentLogProfile(), and onZubleSettingsModified().
|
private |
ID for the log manager's event timer.
Definition at line 526 of file ZblLogManager.h.
Referenced by isCommandLineLogging(), and timerEvent().
|
staticprivate |
The one and only ZblLogManager object in this process.
Definition at line 521 of file ZblLogManager.h.
Referenced by createLogBufferModel(), isCommandLineLogging(), Zbl::ZblLogCategory::registerCategory(), zInit(), zInstance(), and zMessageHandler().
|
staticprotected |
The bundle ID for the zuble application settings = "default".
This bundle ID is used by the log manager to obtain application settings that control the log manager. WARNING: this bundle ID is reserved for use by Zuble!
Definition at line 491 of file ZblLogManager.h.
Referenced by isCommandLineLogging(), onSettingsBundleAvailable(), setApplicationObject(), and updateApplicationSettings().
Zuble documentation copyright © 2019 Bob Dinitto. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Zuble is a derivative work of Qt version 5. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.