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();
113 qDebug() <<
"LOG FILE LOCATION: " << actualLocation;
117 qDebug() <<
"LOG FILE DESTINATION: " << actualLocation;
119 QDir logDir(actualLocation);
123 logDir.mkpath(actualLocation);
129 QDateTime now = QDateTime::currentDateTime();
130 QString nowString = now.toString(
"yyyy:MM:dd:hh:mm:ss:zzz");
132 QString logFilePath(QDir::cleanPath(actualLocation));
136 logFilePath += nowString;
141 logFilePath +=
".log";
144 logFilePath +=
".log.json";
147 logFilePath +=
".log.not-xml";
151 qDebug() <<
"LOG FILE PATH: " << logFilePath;
155 if(!
m_outputFile.open(QFile::WriteOnly | QFile::Truncate | QIODevice::Text))
157 qCritical() <<
"WARNING: Can't open log output file: " << logFilePath;
169 qCritical() <<
"WARNING: Can't write log file information record: " 197 QString creationTime,
198 QByteArray creationZone)
200 QUuid uuid(QUuid::createUuid());
202 QByteArray ba(uuid.toByteArray());
204 qint64 bytesWritten = logFile.write(ba);
206 if(bytesWritten == -1)
211 QString hostVersion(
"%1.%2.%3");
221 info.insert(
"host-version", hostVersion);
224 info.insert(
"creation-zone", creationZone);
225 info.insert(
"creation-time", creationTime);
227 QJsonObject jsonInfo(QJsonObject::fromVariantMap(info));
229 QJsonDocument doc(jsonInfo);
231 ba = doc.toJson(QJsonDocument::Compact);
235 bytesWritten = logFile.write(ba);
237 return (bytesWritten != -1);
282 row.append(QVariant(logMsg.
m_text));
284 row.append(QVariant::fromValue<int>(logMsg.
m_line));
285 row.append(QVariant(logMsg.
m_file));
310 bool fileParamsChanged =
false;
314 fileParamsChanged =
true;
338 QTextStream str(&msgBuffer);
351 str <<
"FATAL ERROR: ";
358 str <<
"\n>line: " << msg.
m_line 359 <<
" >file: " << msg.
m_file 370 QJsonArray logRecord;
373 logRecord.push_back(QJsonValue(msg.
m_category));
374 logRecord.push_back(QJsonValue(QString(
m_logSource)));
375 logRecord.push_back(QJsonValue(msg.
m_text));
376 logRecord.push_back(QJsonValue(msg.
m_function));
377 logRecord.push_back(QJsonValue(msg.
m_line));
378 logRecord.push_back(QJsonValue(msg.
m_file));
382 doc.setArray(logRecord);
384 QByteArray ba(doc.toJson(QJsonDocument::Compact));
QString m_logSource
String that will be written to the "source" field of the log file.
QString m_hostVersionBulid
Build name of the host executable application.
quint64 m_nextRecordNumber
A running counter to generate log record numbers.
QString m_hostName
Name of the host executable application.
ZTableModel * m_logBuffer
Pointer to the log manager's log record histogram buffer.
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...
int m_hostVersionMinor
Minor version of the host executable application.
QString formatTextMessage(const ZblLogMessage &msg)
int m_hostVersionMajor
Major version of the host executable application.
void outputJsonMessage(const ZblLogMessage &msg)
LogFileFormat m_fileFormat
The current logger output file format.
void outputParametersUpdated(QVariant logParams)
ZblLogParams m_logParam
Zuble logging output parameters.
bool writeFileInformation(QFile &logFile, QString creationTime, QByteArray creationZone)
QString m_appName
Application name that will be written to log file.
bool m_enableModelOutput
Enables log output to log histogram buffer.
QTextStream m_outputStream
The log output stream object.
void outputLogMessage(QVariant message)
Outputs a log message to the log histogram buffer and/or a file and/or stdout.
bool m_outFileActive
true if output file object is opened and accepting data, false otherwise.
This two dimensional table model is used to store and manipulate data.
QString m_logOutputDir
Directory in which log files are created.
void outputTextMessage(const ZblLogMessage &msg)
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...
ZblLogWorker(QObject *parent=0)
bool zInit(const QString &logSource, ZTableModel *logBuffer)
Initializes the ZblLogWorker object. This method should be called after the ZblLogWorker object has b...
bool m_enableFileOutput
Enables log output to file.
QFile m_outputFile
The log output file object.
bool m_flush
true = flush output buffers and close streams before returning (used for fatal/abort messages) ...
int m_hostVersionPatch
Patch version of the host executable application.
bool m_enableLogging
Enables Zuble logging.
void setOutputParameters(QVariant logParams)
Sets the output parameters for the log worker object.
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...
bool m_enableDetails
Logs will include detailed debugging information.