36 #include <QStringBuilder> 37 #include <QTemporaryFile> 40 #include <QJsonObject> 41 #include <QJsonDocument> 44 #include <QCoreApplication> 61 m_outFileActive(false),
62 m_nextRecordNumber(0),
63 m_hostVersionMajor(0),
64 m_hostVersionMinor(0),
77 static bool initialized =
false;
90 m_appName = qApp->property(
"org_zuble_appName").toString();
91 m_hostName = qApp->property(
"org_zuble_host_name").toString();
115 qDebug() <<
"LOG FILE LOCATION: " << actualLocation;
119 qDebug() <<
"LOG FILE DESTINATION: " << actualLocation;
121 QDir logDir(actualLocation);
125 logDir.mkpath(actualLocation);
131 QDateTime now = QDateTime::currentDateTime();
132 QString nowString = now.toString(
"yyyy:MM:dd:hh:mm:ss:zzz");
134 QString logFilePath(QDir::cleanPath(actualLocation));
138 logFilePath += nowString;
143 logFilePath +=
".log";
146 logFilePath +=
".log.json";
149 logFilePath +=
".log.not-xml";
153 qDebug() <<
"LOG FILE PATH: " << logFilePath;
157 if(!
m_outputFile.open(QFile::WriteOnly | QFile::Truncate | QIODevice::Text))
159 qCritical() <<
"WARNING: Can't open log output file: " << logFilePath;
171 qCritical() <<
"WARNING: Can't write log file information record: " 199 QString creationTime,
200 QByteArray creationZone)
202 QUuid uuid(QUuid::createUuid());
204 QByteArray ba(uuid.toByteArray());
206 qint64 bytesWritten = logFile.write(ba);
208 if(bytesWritten == -1)
213 QString hostVersion(
"%1.%2.%3");
223 info.insert(
"host-version", hostVersion);
226 info.insert(
"creation-zone", creationZone);
227 info.insert(
"creation-time", creationTime);
229 QJsonObject jsonInfo(QJsonObject::fromVariantMap(info));
231 QJsonDocument doc(jsonInfo);
233 ba = doc.toJson(QJsonDocument::Compact);
237 bytesWritten = logFile.write(ba);
239 return (bytesWritten != -1);
284 row.append(QVariant(logMsg.
m_text));
286 row.append(QVariant::fromValue<int>(logMsg.
m_line));
287 row.append(QVariant(logMsg.
m_file));
312 bool fileParamsChanged =
false;
316 fileParamsChanged =
true;
340 QTextStream str(&msgBuffer);
353 str <<
"FATAL ERROR: ";
360 str <<
"\n>line: " << msg.
m_line 361 <<
" >file: " << msg.
m_file 372 QJsonArray logRecord;
375 logRecord.push_back(QJsonValue(msg.
m_category));
376 logRecord.push_back(QJsonValue(QString(
m_logSource)));
377 logRecord.push_back(QJsonValue(msg.
m_text));
378 logRecord.push_back(QJsonValue(msg.
m_function));
379 logRecord.push_back(QJsonValue(msg.
m_line));
380 logRecord.push_back(QJsonValue(msg.
m_file));
384 doc.setArray(logRecord);
386 QByteArray ba(doc.toJson(QJsonDocument::Compact));
void setOutputParameters(QVariant logParams)
Sets the output parameters for the log worker object.
Q_INVOKABLE void appendCells(QVariant data, bool truncateModel=false)
Asynchronously converts an array of cell data into one or more rows of model data and appends it to t...
QFile m_outputFile
The log output file object.
void outputLogMessage(QVariant message)
Outputs a log message to the log histogram buffer and/or a file and/or stdout.
LogFileFormat m_fileFormat
The current logger output file format.
QString m_hostName
Name of the host executable application.
void outputTextMessage(const ZblLogMessage &msg)
bool writeFileInformation(QFile &logFile, QString creationTime, QByteArray creationZone)
ZTableModel * m_logBuffer
Pointer to the log manager's log record histogram buffer.
bool m_enableModelOutput
Enables log output to log histogram buffer.
int m_hostVersionPatch
Patch version of the host executable application.
void outputParametersUpdated(QVariant logParams)
void outputJsonMessage(const ZblLogMessage &msg)
ZblLogParams m_logParam
Zuble logging output parameters.
QString m_appName
Application name that will be written to log file.
QTextStream m_outputStream
The log output stream object.
ZblLogAgent(QObject *parent=nullptr)
This two dimensional table model is used to store and manipulate data.
QString m_logOutputDir
Directory in which log files are created.
quint64 m_nextRecordNumber
A running counter to generate log record numbers.
bool zInit(const QString &logSource, ZTableModel *logBuffer)
Initializes the ZblLogAgent object. This method should be called after the ZblLogAgent object has bee...
This class contains the Zuble logging parameters that control log output.
static QString resolvePath(const QString &path, bool includeUrlScheme=true)
Converts relative file paths into canonical file paths. Paths prefixed with prefix are mapped relativ...
bool m_enableFileOutput
Enables log output to file.
QString m_logSource
String that will be written to the "source" field of the log file.
int m_hostVersionMinor
Minor version of the host executable application.
bool m_flush
true = flush output buffers and close streams before returning (used for fatal/abort messages) ...
bool m_outFileActive
true if output file object is opened and accepting data, false otherwise.
QString m_hostVersionBulid
Build name of the host executable application.
bool m_enableLogging
Enables Zuble logging.
int m_hostVersionMajor
Major version of the host executable application.
This class is used to transfer log messages between threads.
bool m_enableStdOutput
Enables log output to stdout.
QList< QVariant > ZDataRow
Represents a single row (or column for column headers) of data cell values for a single role...
QString formatTextMessage(const ZblLogMessage &msg)
bool m_enableDetails
Logs will include detailed debugging information.