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
ZblLogManager.h
Go to the documentation of this file.
1 /*
2  * Zuble - A run-time system for QML/Javascript applications
3  * Copyright (C) 2015 Bob Dinitto
4  *
5  * Filename: ZblLogManager.h
6  * Created on: 4/19/2015
7  * Author: Bob Dinitto
8  *
9  * Zuble is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  */
24 
25 #ifndef ZBLLOGMANAGER_H
26 #define ZBLLOGMANAGER_H
27 
28 #include <QObject>
29 #include <QMutex>
30 #include <QStringList>
31 #include <QFile>
32 #include "zglobal.h"
33 #include "ZTableModel.h"
34 #include "ZblLogParams.h"
35 
36 #define zLogMan (Zbl::ZblLogManager::zInstance())
37 
38 //Q_DECLARE_METATYPE(QtMsgType)
39 //Q_DECLARE_METATYPE(QMessageLogContext)
40 
41 namespace Zbl
42 {
43 class ZblLogCategory;
44 class ZTableModel;
45 class ZSettings;
46 class ZApplication;
47 class ZblLogWorker;
48 
70 class ZblLogManager : public QObject
71 {
72  friend class Zblcore;
73  friend class ZblLogCategory;
74  friend class ZblLogWorker;
75  //friend class ZLogReader;
76 
77  //typedef QHash<int, QByteArray> zLogFields;
78 
79  Q_OBJECT
80  Q_ENUMS(logFields)
81 
82 
83 public:
84 
89  enum logFields
90  {
99  };
100 
106  {
114  };
115 
116 
117  explicit ZblLogManager(QObject *parent = 0);
118 
119  virtual ~ZblLogManager();
120 
127  static ZblLogManager& zInit(QObject* parent);
128 
134  static ZblLogManager& zInstance();
135 
142  Q_INVOKABLE QObject* getLogBuffer();
143 
144 
150  Q_INVOKABLE int getLogBufferRoleCount();
151 
152 
153 
162  Q_INVOKABLE QObject* getLogRules();
163 
164 
165 
171  virtual void timerEvent(QTimerEvent * event);
172 
184  ZTableModel* createLogBufferModel(QObject* parent = NULL);
185 
186 
187 
188  // return the list of registered categories for javascript
189 
190  // return the list of unregistered categories for javascript
191 
192  // read configuration files and apply default
193  // algorithm
194 
195  // provide API for javascript to read/write configuration settings
196 
197  // write configuration files
198 
199 signals:
200 
201 public slots:
202 
212  bool registerLogCategory(const QString logCategory);
213 
214 
215 
222  void onLogProfileModified(const QString& path);
223 
230  void onZubleSettingsModified(const QString& path);
231 
249  void onLogWorkerOutputParametersUpdated(QVariant logParams);
250 
256  void onSettingsBundleAvailable(QString bundleId);
257 
265  bool loadFilterRules(const QString& logProfileBundleID);
266 
267 
268 
276  void onRuleModelModified(int dataRole, int rowNumber);
277 
283  void saveFilterRules();
284 
292 
301  bool appendRuleModelCategory(const QString& logCategory);
302 
303 
304 
305 
306 protected:
307 
309 
322  QString getQtLogRule(const QString& category, const QString& level, bool enabled);
323 
333  QString getQtLogRulesForRow(int rowNumber);
334 
340  void setQtLogRulesFromModel();
341 
351  bool createRuleModel();
352 
353 
354 #if 0
355 
363  //bool updateMessageHandlerStatus();
364 #endif
365 
372  bool isCommandLineLogging();
373 
374 
381  bool startLogThread();
382 
387  void stopLogThread();
388 
389 
398  bool populateMetaRules();
399 
400 
409  void setApplicationObject(ZApplication* appObject);
410 
412 
419 
427  bool loadCurrentLogProfile();
428 
444  static QString createTemporaryLogProfile(
445  const QString& nameTemplate,
446  bool remove = false);
447 
461  static QString getLogSettingsMetadata();
462 
463 
464  static LogFileFormat fileFormatFromString(const QString& logFileFormat);
465 
472  void setLogOutputParameters();
473 
474 
482  static const QString m_currentLogSettingsBundleId;
483 
491  static const QString m_zubleSettingsBundleId;
492 
496  static const QString m_defaultOutputFilePath;
497 
498 private:
499 
507  static void zMessageHandler(QtMsgType msgType,
508  const QMessageLogContext& logCtx,
509  const QString& text);
510 
511 
516 
522 
527 
528 
536 
542 
543 
548  QThread m_logThread;
549 
556 
564 
569 
574 
575 
580 
587  static const QString m_logFilterRulesKey;
588 
596 
604 
605 
606 
615  static int m_maxBufferSize;
616 
622  static const QString m_profileMetadata;
623 
628  static const int m_logBufRoleCount;
629 
630 
639 
645 
646 
650  QString m_LogSource;
651 
657  QtMessageHandler m_originalMsgHandler;
658 
659 };
660 
661 } // Zbl
662 
663 #endif // ZBLLOGMANAGER_H
void onSettingsBundleAvailable(QString bundleId)
Responds to newly loaded settings bundles.
The Zuble Log Manager is a singleton object that controls logging in Zuble applications.
Definition: ZblLogManager.h:70
static const QString m_profileMetadata
Log profile metadata defines logger settings that are stored in a log profile.
ZblLogWorker * m_logWorker
A background thread worker object to handle logging rules and log record output.
void populateRegisteredRules()
Appends all log categories that have so far been registered with a call to ZblLogManager::registerLog...
void updateApplicationSettings()
void setQtLogRulesFromModel()
Sets Qt&#39;s internal logging rules from data contained in log manager&#39;s logging rules model...
#define ZBL_DECLARE_LOGGED_OBJECT
Definition: zglobal.h:94
Q_INVOKABLE QObject * getLogBuffer()
Obtain the log buffer data model.
void onLogWorkerOutputParametersUpdated(QVariant logParams)
Synchronizes log manager and log worker output parameters.
static LogFileFormat fileFormatFromString(const QString &logFileFormat)
static ZblLogManager & zInit(QObject *parent)
Construct, initialize and obtain a reference to Zuble&#39;s log manager object.
bool populateMetaRules()
Appends all log categories defined in the Zuble application&#39;s zblconfig.xml configuration file to the...
bool loadCurrentLogProfile()
Replaces the current log settings with those from the specified file.
ZRoleNames m_bufferRoles
A hash of log buffer column numbers to column field names.
This class provides a thread-safe log message back end for the Zuble log manager. ...
Definition: ZblLogWorker.h:50
bool registerLogCategory(const QString logCategory)
Adds the specified log category to the registered log category list.
bool appendRuleModelCategory(const QString &logCategory)
Adds a new category to the rule model. If the category already exists in the rule model the request t...
enum Zbl::logFileFormat LogFileFormat
Specifies the output format for Zuble log files.
ruleFields
Roles for the logging rules data model.
void setApplicationObject(ZApplication *appObject)
Connects the log manager to appropriate Zuble core plugin signals and attempts to load the current lo...
static int m_maxBufferSize
The number of logging records the circular log buffer will attempt to hold.
bool m_loadingProfile
true when log manager is currently loading a log profile, false otherwise
bool loadFilterRules(const QString &logProfileBundleID)
Loades the log filter rules from the specified log profile into the log rule model.
void onRuleModelModified(int dataRole, int rowNumber)
Responds to changes in the rule model by updating Qt&#39;s internal rule model and the current log settin...
ZDataRow m_modelBooleanRow
A data row to use as a template for constructing role rows.
ZDataRow m_modelCategoryRow
A data row to use as a template for constructing role rows.
void updateLogProfileSettings()
Loads a new copy of the log profile settings from the settings file.
ZblLogParams m_logParam
Current Zuble logging parameters.
logFileFormat
Specifies the output format for Zuble log files.
Definition: zglobal.h:197
The core Zuble QML Extension plugin class.
Definition: Zblcore.h:78
Definition: ZAndGate.cpp:6
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.
static ZblLogManager & zInstance()
Obtain a reference to Zuble&#39;s log manager object.
ZTableModel * createLogBufferModel(QObject *parent=NULL)
Creates a new log record data model by appending the appropriate data rules. The caller assumes owner...
QMap< int, QList< QVariant > > ZRoleRow
Represents a single row (or column for column headers) of data cell values for multiple roles...
Definition: ZTableModel.h:63
static const QString m_defaultOutputFilePath
TBD: currently unused!
ZTableModel * m_logBuffer
Zuble&#39;s log buffer provides a viewable record of recent log activity.
This two dimensional table model is used to store and manipulate data.
Definition: ZTableModel.h:96
ZTableModel * m_logRules
A data model containing the current logging rules in effect for each known log category.
void saveFilterRules()
Saves the current state of the logging rules data model to the current log profile.
QString getQtLogRulesForRow(int rowNumber)
Returns a Qt logging rule string for all logging levels for the specified row (log category) in the l...
virtual void timerEvent(QTimerEvent *event)
Timer is used to flush excess log records from the log record buffer.
Q_INVOKABLE int getLogBufferRoleCount()
Obtain the number of roles in the log buffer data model.
QtMessageHandler m_originalMsgHandler
Pointer to the original (non-Zuble) message handler, or nullptr if Zuble logging has not yet been ena...
Wraps the QSettings class and implements a JSON-based backend for storing the settings data...
Definition: ZSettings.h:44
This class contains the Zuble logging parameters that control log output.
Definition: ZblLogParams.h:38
bool m_syncProfiles
true if all application instances update the same log profile, false if each instance updates a separ...
static const QString m_zubleSettingsBundleId
The bundle ID for the zuble application settings = "default".
bool startLogThread()
Starts log manager&#39;s background thread.
void onLogProfileModified(const QString &path)
Responds to changes to the current log settings by replacing the log profile with the current log set...
static QString createTemporaryLogProfile(const QString &nameTemplate, bool remove=false)
Creates an empty file with a unique file name in the log profile directory.
QHash< int, QByteArray > ZRoleNames
Maps role numbers to role names as a hash table object.
Definition: ZTableModel.h:44
void onZubleSettingsModified(const QString &path)
Responds to changes in the Zuble application settingsby updating log manager&#39;s internal state...
Zuble&#39;s Singleton Application Object.
Definition: ZApplication.h:54
static ZblLogManager * m_zLog
The one and only ZblLogManager object in this process.
Zuble objects embed this class to save local logging state.
void stopLogThread()
Stops log manager&#39;s background thread.
static const int m_logBufRoleCount
The number of roles contained in a log file record.
static QString getLogSettingsMetadata()
Returns an xml data structure that defines the zuble application&#39;s log settings.
static void zMessageHandler(QtMsgType msgType, const QMessageLogContext &logCtx, const QString &text)
Zuble&#39;s Qt message handler.
ZSettings * m_logSettings
A ZSettings object to track the application settings for changes that control Zuble logging...
QString m_LogSource
String inserted into the "source" field of log records.
bool createRuleModel()
Creates the log manager&#39;s log rules data model and initializes associated variables used to optimize ...
ZSettings * m_profileSettings
A ZSettings object to track the current log profile for changes to the profile settings.
ZblLogManager(QObject *parent=0)
ZRoleRow m_modelRoleRow
A role row to use as a template for adding logging rules to the rule model.
bool isCommandLineLogging()
Returns true if -zl option is passed in on command line.
logFields
Roles for the log record data model.
Definition: ZblLogManager.h:89
static const QString m_logFilterRulesKey
The log filter rules key = "log-filter-rules".
QThread m_logThread
A background thread to handle logging rules and log record output.
QList< QVariant > ZDataRow
Represents a single row (or column for column headers) of data cell values for a single role...
Definition: ZTableModel.h:57
static const QString m_currentLogSettingsBundleId
The bundle ID for the current logging profile = "current-log-profile".
int m_timerID
ID for the log manager&#39;s event timer.
Q_INVOKABLE QObject * getLogRules()
Obtain the logging rules data model.
void setLogOutputParameters()
Gathers the application and log profile settings that affect log output and synchronizes those parame...