mirror of
https://github.com/chylex/Nextcloud-Desktop.git
synced 2025-04-26 13:15:47 +02:00
parent
48f4c1e9e1
commit
990ce6ed05
src/libsync
@ -32,6 +32,9 @@
|
||||
#include <io.h> // for stdout
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
constexpr int CrashLogSize = 20;
|
||||
}
|
||||
namespace OCC {
|
||||
|
||||
QtMessageHandler s_originalMessageHandler = nullptr;
|
||||
@ -52,6 +55,7 @@ static void mirallLogCatcher(QtMsgType type, const QMessageLogContext &ctx, cons
|
||||
|
||||
if(type == QtFatalMsg) {
|
||||
if (!logger->isNoop()) {
|
||||
logger->dumpCrashLog();
|
||||
logger->close();
|
||||
}
|
||||
#if defined(Q_OS_WIN)
|
||||
@ -71,7 +75,8 @@ Logger *Logger::instance()
|
||||
Logger::Logger(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
qSetMessagePattern("%{time yyyy-MM-dd hh:mm:ss:zzz} [ %{type} %{category} ]%{if-debug}\t[ %{function} ]%{endif}:\t%{message}");
|
||||
qSetMessagePattern(QStringLiteral("%{time yyyy-MM-dd hh:mm:ss:zzz} [ %{type} %{category} ]%{if-debug}\t[ %{function} ]%{endif}:\t%{message}"));
|
||||
_crashLog.resize(CrashLogSize);
|
||||
#ifndef NO_MSG_HANDLER
|
||||
s_originalMessageHandler = qInstallMessageHandler(mirallLogCatcher);
|
||||
#else
|
||||
@ -135,6 +140,8 @@ void Logger::doLog(const QString &msg)
|
||||
{
|
||||
{
|
||||
QMutexLocker lock(&_mutex);
|
||||
_crashLogIndex = (_crashLogIndex + 1) % CrashLogSize;
|
||||
_crashLog[_crashLogIndex] = msg;
|
||||
if (_logstream) {
|
||||
(*_logstream) << msg << endl;
|
||||
if (_doFileFlush)
|
||||
@ -267,6 +274,17 @@ void Logger::setLogRules(const QSet<QString> &rules)
|
||||
QLoggingCategory::setFilterRules(rules.toList().join(QLatin1Char('\n')));
|
||||
}
|
||||
|
||||
void Logger::dumpCrashLog()
|
||||
{
|
||||
QFile logFile(QDir::tempPath() + QStringLiteral("/" APPLICATION_NAME "-crash.log"));
|
||||
if (logFile.open(QFile::WriteOnly)) {
|
||||
QTextStream out(&logFile);
|
||||
for (int i = 1; i <= CrashLogSize; ++i) {
|
||||
out << _crashLog[(_crashLogIndex + i) % CrashLogSize] << QLatin1Char('\n');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool compressLog(const QString &originalName, const QString &targetName)
|
||||
{
|
||||
#ifdef ZLIB_FOUND
|
||||
|
@ -95,6 +95,8 @@ public:
|
||||
}
|
||||
void setLogRules(const QSet<QString> &rules);
|
||||
|
||||
void dumpCrashLog();
|
||||
|
||||
signals:
|
||||
void logWindowLog(const QString &);
|
||||
|
||||
@ -119,6 +121,8 @@ private:
|
||||
QString _logDirectory;
|
||||
bool _temporaryFolderLogDir = false;
|
||||
QSet<QString> _logRules;
|
||||
QVector<QString> _crashLog;
|
||||
int _crashLogIndex = 0;
|
||||
};
|
||||
|
||||
} // namespace OCC
|
||||
|
Loading…
Reference in New Issue
Block a user