mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 13:43:49 +02:00
Storing log to file - initial
This commit is contained in:
parent
ee1eb25dfa
commit
505ed5bc64
3 changed files with 19 additions and 7 deletions
|
@ -7,32 +7,44 @@
|
|||
//
|
||||
|
||||
#include "FileLogger.h"
|
||||
#include "HifiSockAddr.h"
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
|
||||
FileLogger::FileLogger() : _lines(NULL) {
|
||||
QHostAddress clientAddress = QHostAddress(getHostOrderLocalAddress());
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
_fileName = QString("hifi-log_%1_%2.txt").arg(clientAddress.toString(), now.toString("yyyy-MM-dd_hh.mm.ss"));
|
||||
setExtraDebugging(false);
|
||||
}
|
||||
|
||||
QStringList FileLogger::getLogData(QString searchText) {
|
||||
|
||||
if (searchText.isEmpty()) {
|
||||
return _lines;
|
||||
}
|
||||
|
||||
// wait for adding new log data while iterating over _lines
|
||||
// pthread_mutex_lock(& _mutex);
|
||||
_mutex.lock();
|
||||
QStringList filteredList;
|
||||
for (int i = 0; i < _lines.size(); ++i) {
|
||||
if (_lines[i].contains(searchText, Qt::CaseInsensitive)) {
|
||||
filteredList.append(_lines[i]);
|
||||
}
|
||||
}
|
||||
// pthread_mutex_unlock(& _mutex);
|
||||
_mutex.unlock();
|
||||
return filteredList;
|
||||
}
|
||||
|
||||
void FileLogger::addMessage(QString message) {
|
||||
_mutex.lock();
|
||||
emit logReceived(message);
|
||||
_lines.append(message);
|
||||
|
||||
// TODO: append message to file
|
||||
QFile file(_fileName);
|
||||
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) {
|
||||
QTextStream out(&file);
|
||||
out << message;
|
||||
}
|
||||
_mutex.unlock();
|
||||
}
|
|
@ -22,6 +22,8 @@ public:
|
|||
|
||||
private:
|
||||
QStringList _lines;
|
||||
QString _fileName;
|
||||
QMutex _mutex;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -110,9 +110,7 @@ void LogDialog::resizeEvent(QResizeEvent*) {
|
|||
void LogDialog::appendLogLine(QString logLine) {
|
||||
if (isVisible()) {
|
||||
pthread_mutex_lock(& _mutex);
|
||||
|
||||
QString line = logLine.replace(QRegExp("node"), "<b>node</b>");
|
||||
_logTextBox->appendHtml(line);
|
||||
_logTextBox->appendHtml(logLine.simplified());
|
||||
pthread_mutex_unlock(& _mutex);
|
||||
_logTextBox->ensureCursorVisible();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue