Qx v0.5.7
Qt Extensions Library
Loading...
Searching...
No Matches
qx-applicationlogger.h
1#ifndef APPLICATIONLOGGER_H
2#define APPLICATIONLOGGER_H
3
4// Shared Lib Support
5#include "qx/io/qx_io_export.h"
6
7// Qt Includes
8#include <QString>
9#include <QStringList>
10#include <QRegularExpression>
11
12// Qx Includes
13#include <qx/core/qx-error.h>
14#include <qx/io/qx-textstreamwriter.h>
15
17
18namespace Qx
19{
20
21class QX_IO_EXPORT ApplicationLogger
22{
23//-Class Variables----------------------------------------------------------------------------------------------------
24private:
25 static inline const QString HEADER_TEMPLATE = u"[ %1 Execution Log ] (%2) : %3"_s;
26 // NOTE: Changes to the members of this class might require changes to this pattern
27 static inline const QRegularExpression HEADER_PATTERN = QRegularExpression(uR"(^\[ .* Execution Log \] \‍(.*\) : .+)"_s,
29 static inline const QString NO_PARAMS = u"*None*"_s;
30 static inline const QString EVENT_TEMPLATE = u" - <%1> [%2] %3"_s;
31 static inline const QString ERR_TEMPLATE = u" - <%1> [%2] %3) %4 - %5"_s;
32 static inline const QString COMMANDLINE_LABEL = u"Arguments:"_s;
33 static inline const QString EVENTS_LABEL = u"Events:"_s;
34 static inline const QString FINISH_TEMPLATE = u"---------- Execution finished %1 (Code %2) ----------"_s;
35 static inline const QString FINISH_SUCCESS = u"successfully"_s;
36 static inline const QString FINISH_ERR = u"prematurely"_s;
37
38//-Instance Variables-------------------------------------------------------------------------------------------------
39private:
40 // Setup
41 QString mFilePath;
42 QString mAppName;
43 QString mAppVersion;
44 QString mAppArguments;
45 QDateTime mConstructionTimeStamp;
46 int mMaxEntries;
47
48 // Working var
49 TextStreamWriter mTextStreamWriter;
50 IoOpReport mErrorStatus;
51
52//-Constructor--------------------------------------------------------------------------------------------------------
53public:
55 ApplicationLogger(const QString& filePath);
56 ApplicationLogger(const QString& filePath, const QCoreApplication* app);
57
58//-Instance Functions-------------------------------------------------------------------------------------------------
59public:
60 // Configure
61 QString filePath() const;
62 QString applicationName() const;
63 QString applicationVersion() const;
64 QString applicationArguments() const;
65 int maximumEntries() const;
66
67 void setFilePath(const QString& path);
68 void setApplicationName(const QString& name);
69 void setApplicationVersion(const QString& version);
70 void setApplicationArguments(const QString& args);
71 void setApplicationArguments(const QStringList& args);
72 void setMaximumEntries(int max);
73
74 // Operate
75 IoOpReport openLog();
76 IoOpReport recordVerbatim(const QString& text);
77 IoOpReport recordErrorEvent(const QString& src, const Error& error);
78 IoOpReport recordGeneralEvent(const QString& src, const QString& event);
79 IoOpReport finish(int returnCode);
80
81 // Status
82 IoOpReport status() const;
83 void resetStatus();
84 bool hasError() const;
85 bool isOpen() const;
86};
87
88}
89#endif // APPLICATIONLOGGER_H
The ApplicationLogger class acts as a convenient means of producing an execution log for an applicati...
Definition qx-applicationlogger.h:22
The Error class acts as an interface for an extensible variety of error objects.
Definition qx-error.h:38
The IoOpReport class is a container for details regarding the outcome of an IO operation.
Definition qx-ioopreport.h:53
The TextStreamWriter class is a specialized wrapper for QTextStream that narrows and simplifies its u...
Definition qx-textstreamwriter.h:19
The Qx namespace is the main namespace through which all non-global functionality of the Qx library i...
Definition qx-processwaiter.cpp:5
The qx-error.h header file provides access to the Error interface.