Keep more logs
This commit is contained in:
parent
23f15b1edd
commit
a3c73ad12e
@ -64,6 +64,7 @@ AppLogController::AppLogController(QObject *parent) : QAbstractListModel(parent)
|
|||||||
QString fileName = path + "/nymea-app.log";
|
QString fileName = path + "/nymea-app.log";
|
||||||
m_logFile.setFileName(fileName);
|
m_logFile.setFileName(fileName);
|
||||||
|
|
||||||
|
QByteArray oldContent;
|
||||||
if (QFile::exists(fileName)) {
|
if (QFile::exists(fileName)) {
|
||||||
if (QFile::exists(fileName + ".old")) {
|
if (QFile::exists(fileName + ".old")) {
|
||||||
QFile::remove(fileName + ".old");
|
QFile::remove(fileName + ".old");
|
||||||
@ -71,13 +72,18 @@ AppLogController::AppLogController(QObject *parent) : QAbstractListModel(parent)
|
|||||||
QFile::rename(fileName, fileName + ".old");
|
QFile::rename(fileName, fileName + ".old");
|
||||||
QFile oldFile(fileName + ".old");
|
QFile oldFile(fileName + ".old");
|
||||||
if (oldFile.open(QFile::ReadOnly)) {
|
if (oldFile.open(QFile::ReadOnly)) {
|
||||||
m_buffer.append(QString(oldFile.readAll()).split('\n'));
|
oldFile.seek(qMax((long long)0, oldFile.size() - 1024 * 1024));
|
||||||
|
oldContent = oldFile.readAll();
|
||||||
|
oldFile.close();
|
||||||
|
|
||||||
|
m_buffer.append(QString(oldContent).split('\n'));
|
||||||
for (int i = 0; i < m_buffer.count(); i++) {
|
for (int i = 0; i < m_buffer.count(); i++) {
|
||||||
m_types.append(TypeInfo);
|
m_types.append(TypeInfo);
|
||||||
}
|
}
|
||||||
m_types.append(TypeWarning);
|
m_types.append(TypeWarning);
|
||||||
m_buffer.append("**** App restart ****");
|
m_buffer.append("**** App restart ****");
|
||||||
oldFile.close();
|
|
||||||
|
oldContent.append("\n\n**** App restart ****\n\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
@ -93,6 +99,8 @@ AppLogController::AppLogController(QObject *parent) : QAbstractListModel(parent)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qDebug() << "App log opened at" << fileName;
|
qDebug() << "App log opened at" << fileName;
|
||||||
|
m_logFile.write(oldContent);
|
||||||
|
|
||||||
|
|
||||||
if (enabled()) {
|
if (enabled()) {
|
||||||
activate();
|
activate();
|
||||||
@ -164,6 +172,11 @@ void AppLogController::toClipboard()
|
|||||||
QGuiApplication::clipboard()->setText(completeLog);
|
QGuiApplication::clipboard()->setText(completeLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString AppLogController::logFile() const
|
||||||
|
{
|
||||||
|
return m_logFile.fileName();
|
||||||
|
}
|
||||||
|
|
||||||
void AppLogController::logMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
|
void AppLogController::logMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &message)
|
||||||
{
|
{
|
||||||
s_oldLogMessageHandler(type, context, message);
|
s_oldLogMessageHandler(type, context, message);
|
||||||
|
|||||||
@ -42,6 +42,7 @@ class AppLogController : public QAbstractListModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool canWriteLogs READ canWriteLogs CONSTANT)
|
Q_PROPERTY(bool canWriteLogs READ canWriteLogs CONSTANT)
|
||||||
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
|
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
|
||||||
|
Q_PROPERTY(QString logFile READ logFile CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Type {
|
enum Type {
|
||||||
@ -71,6 +72,8 @@ public:
|
|||||||
|
|
||||||
Q_INVOKABLE void toClipboard();
|
Q_INVOKABLE void toClipboard();
|
||||||
|
|
||||||
|
QString logFile() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void enabledChanged();
|
void enabledChanged();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user