Skip to content
This repository was archived by the owner on Mar 2, 2024. It is now read-only.

Commit 705efa2

Browse files
committed
添加log记录
1 parent 728ea33 commit 705efa2

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

main.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,37 @@
11
#include "systemtray.h"
22
#include <DAboutDialog>
33
#include <DApplication>
4+
#include <DLog>
45

56
DWIDGET_USE_NAMESPACE
6-
7+
void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
8+
QByteArray localMsg = msg.toLocal8Bit();
9+
switch (type) {
10+
case QtDebugMsg:
11+
fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
12+
break;
13+
case QtInfoMsg:
14+
fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
15+
break;
16+
case QtWarningMsg:
17+
fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
18+
break;
19+
case QtCriticalMsg:
20+
fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
21+
break;
22+
case QtFatalMsg:
23+
fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
24+
break;
25+
}
26+
}
727
int main(int argc, char *argv[]) {
828
DApplication::loadDXcbPlugin();
929
DApplication app(argc, argv);
1030

31+
qInstallMessageHandler(myMessageOutput);
32+
std::freopen((QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/stickyNotes.log").toStdString().c_str(), "a", stderr);
33+
std::cerr << std::endl << std::endl;
34+
1135
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
1236
if (!app.setSingleInstance("DStickyNotes-develop"))
1337
return 0;

0 commit comments

Comments
 (0)