31
31
#include < io.h> // for stdout
32
32
#endif
33
33
34
+ namespace {
35
+ constexpr int CrashLogSize = 20 ;
36
+ }
34
37
namespace OCC {
35
38
36
39
static void mirallLogCatcher (QtMsgType type, const QMessageLogContext &ctx, const QString &message)
@@ -45,6 +48,7 @@ static void mirallLogCatcher(QtMsgType type, const QMessageLogContext &ctx, cons
45
48
46
49
if (type == QtFatalMsg) {
47
50
if (!logger->isNoop ()) {
51
+ logger->dumpCrashLog ();
48
52
logger->close ();
49
53
}
50
54
#if defined(Q_OS_WIN)
@@ -69,6 +73,7 @@ Logger::Logger(QObject *parent)
69
73
, _logDebug(false )
70
74
{
71
75
qSetMessagePattern (QStringLiteral (" %{time MM-dd hh:mm:ss:zzz} [ %{type} %{category} ]%{if-debug}\t [ %{function} ]%{endif}:\t %{message}" ));
76
+ _crashLog.resize (CrashLogSize);
72
77
#ifndef NO_MSG_HANDLER
73
78
qInstallMessageHandler (mirallLogCatcher);
74
79
#else
@@ -132,6 +137,8 @@ void Logger::doLog(const QString &msg)
132
137
{
133
138
{
134
139
QMutexLocker lock (&_mutex);
140
+ _crashLogIndex = (_crashLogIndex + 1 ) % CrashLogSize;
141
+ _crashLog[_crashLogIndex] = msg;
135
142
if (_logstream) {
136
143
(*_logstream) << msg << endl;
137
144
if (_doFileFlush)
@@ -246,6 +253,17 @@ void Logger::setLogRules(const QSet<QString> &rules)
246
253
QLoggingCategory::setFilterRules (tmp);
247
254
}
248
255
256
+ void Logger::dumpCrashLog ()
257
+ {
258
+ QFile logFile (QDir::tempPath () + QStringLiteral (" /" APPLICATION_NAME " -crash.log" ));
259
+ if (logFile.open (QFile::WriteOnly)) {
260
+ QTextStream out (&logFile);
261
+ for (int i = 1 ; i <= CrashLogSize; ++i) {
262
+ out << _crashLog[(_crashLogIndex + i) % CrashLogSize] << QLatin1Char (' \n ' );
263
+ }
264
+ }
265
+ }
266
+
249
267
static bool compressLog (const QString &originalName, const QString &targetName)
250
268
{
251
269
#ifdef ZLIB_FOUND
0 commit comments