modify:
This commit is contained in:
+10
-6
@@ -48,22 +48,26 @@ void messageHandler(QtMsgType type, const QMessageLogContext &context, const QSt
|
||||
}
|
||||
|
||||
// 输出到日志文件, 格式: 时间 - [Level] (文件名:行数, 函数): 消息
|
||||
QString fileName = context.file ? QString::fromUtf8(context.file) : QStringLiteral("unknown");
|
||||
QString fileName = context.file ? QString::fromUtf8(context.file) : QStringLiteral("?");
|
||||
int index = fileName.lastIndexOf(QDir::separator());
|
||||
if (index >= 0)
|
||||
{
|
||||
fileName = fileName.mid(index + 1);
|
||||
}
|
||||
|
||||
const QString funcName = context.function ? QString::fromUtf8(context.function) : QStringLiteral("unknown");
|
||||
QString msgOut = QString("%1-[%2](%3:%4,%5): %6")
|
||||
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz"),colorLevel, fileName, QString(context.line), funcName, msg);
|
||||
const QString funcName = context.function ? QString::fromUtf8(context.function) : QStringLiteral("?");
|
||||
const QString lineText = QString::number(context.line);
|
||||
const QString timestamp = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz");
|
||||
const QString consoleMsg = QString("%1-[%2](%3:%4,%5): %6")
|
||||
.arg(timestamp, colorLevel, fileName, lineText, funcName, msg);
|
||||
const QString fileMsg = QString("%1-[%2](%3:%4,%5): %6")
|
||||
.arg(timestamp, level, fileName, lineText, funcName, msg);
|
||||
|
||||
std::cout << msgOut.toLocal8Bit().constData() << std::endl;
|
||||
std::cout << consoleMsg.toLocal8Bit().constData() << std::endl;
|
||||
|
||||
if (g_file.isOpen())
|
||||
{
|
||||
g_stream << msgOut << "\n";
|
||||
g_stream << fileMsg << "\n";
|
||||
const qint64 now = QDateTime::currentMSecsSinceEpoch();
|
||||
if (type >= QtCriticalMsg || now - g_lastFlushMs >= kLogFlushIntervalMs)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user