#include <QCoreApplication>
#include <QDebug>
#include <QFile>
#include <QTextStream>
void myMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
static QFile logFile("log.txt");
if (!logFile.isOpen())
logFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream ts(&logFile);
switch (type) {
case QtDebugMsg:
ts << "Debug: ";
break;
case QtInfoMsg:
ts << "Info: ";
break;
case QtWarningMsg:
ts << "Warning: ";
break;
case QtCriticalMsg:
ts << "Critical: ";
break;
case QtFatalMsg:
ts << "Fatal: ";
abort();
}
ts << context.file << "(" << context.line << "): " << msg << endl;
}
int main(int argc, char *argv[])
{
qInstallMessageHandler(myMessageHandler);
QCoreApplication a(argc, argv);
qDebug() << "This is a debug message.";
qInfo() << "This is an info message.";
qWarning() << "This is a warning message.";
qCritical() << "This is a critical message.";
return a.exec();
}
13. MySQL 日志
2024-07-11 00:38:03 69 阅读