74 lines
No EOL
1.9 KiB
C++
74 lines
No EOL
1.9 KiB
C++
#include <QApplication>
|
|
#include <QLabel>
|
|
#include <QCoreApplication>
|
|
#include <QDebug>
|
|
#include <QDateTime>
|
|
#include <QFile>
|
|
#include <QTextStream>
|
|
|
|
#include "dock.h"
|
|
|
|
void customMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
|
|
// static QFile logFile("debug_output.log");
|
|
// if (!logFile.isOpen()) {
|
|
// logFile.open(QIODevice::Append | QIODevice::Text);
|
|
// }
|
|
|
|
// QTextStream out(&logFile);
|
|
QTextStream console(stdout);
|
|
|
|
QString levelStr;
|
|
QString colorStart;
|
|
const QString colorEnd = "\033[0m";
|
|
|
|
switch (type) {
|
|
case QtDebugMsg:
|
|
levelStr = "DEBUG";
|
|
colorStart = "\033[36m"; // Cyan
|
|
break;
|
|
case QtInfoMsg:
|
|
levelStr = "INFO";
|
|
colorStart = "\033[32m"; // Green
|
|
break;
|
|
case QtWarningMsg:
|
|
levelStr = "WARNING";
|
|
colorStart = "\033[33m"; // Yellow
|
|
break;
|
|
case QtCriticalMsg:
|
|
levelStr = "CRITICAL";
|
|
colorStart = "\033[31m"; // Red
|
|
break;
|
|
case QtFatalMsg:
|
|
levelStr = "FATAL";
|
|
colorStart = "\033[41m\033[97m"; // Red background, white text
|
|
break;
|
|
}
|
|
|
|
QString time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz");
|
|
|
|
// Plain version for log file
|
|
QString plainText = QString("[%1] [%2] %3 (%4:%5)")
|
|
.arg(time, levelStr, msg, context.file, QString::number(context.line));
|
|
|
|
// Colored level only for console
|
|
QString coloredText = QString("[%1] [%2%3%4] %5 (%6:%7)")
|
|
.arg(time, colorStart, levelStr, colorEnd, msg, context.file, QString::number(context.line));
|
|
|
|
// out << plainText << "\n";
|
|
// out.flush();
|
|
|
|
console << coloredText << "\n";
|
|
console.flush();
|
|
|
|
if (type == QtFatalMsg)
|
|
abort();
|
|
}
|
|
|
|
int main(int argc, char *argv[]) {
|
|
qInstallMessageHandler(customMessageHandler);
|
|
|
|
QApplication app(argc, argv);
|
|
Dock dock{&app};
|
|
|
|
return 0;
|
|
} |