日志
发布日期:2022-07-08 02:55:51 浏览次数:40 分类:技术文章

本文共 906 字,大约阅读时间需要 3 分钟。

日志

#include
#include

void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg)

{
static QMutex mutex;
mutex.lock();

QString text;switch (type){case QtDebugMsg:	text = QString("Debug:");	break;case QtWarningMsg:	text = QString("Warning:");	break;case QtCriticalMsg:	text = QString("Critical:");	break;case QtFatalMsg:	text = QString("Fatal:");}QString context_info = QString("File:(%1) Line:(%2)").arg(QString(context.file)).arg(context.line);QString current_date_time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss ddd");QString current_date = QString("(%1)").arg(current_date_time);QString message = QString("%1 %2 %3 %4").arg(text).arg(context_info).arg(msg).arg(current_date);QFile file("log.txt");file.open(QIODevice::WriteOnly | QIODevice::Append);QTextStream text_stream(&file);text_stream << message << "\r\n";file.flush();file.close();mutex.unlock();

}

转载地址:https://blog.csdn.net/weixin_45955823/article/details/103419302 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:日志
下一篇:日志

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月10日 16时52分44秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章