QT log日志

#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();
}

Qt::Qt Log日志模块_何其不顾四月天-开放原子开发者工作坊

相关推荐

  1. 日常开发

    2024-07-11 00:38:03       44 阅读
  2. ELK的

    2024-07-11 00:38:03       45 阅读
  3. docker查看

    2024-07-11 00:38:03       44 阅读

最近更新

  1. Blazor Webassembly多标签页实现非iframe的实现

    2024-07-11 00:38:03       0 阅读
  2. Lianwei 安全周报|2024.07.22

    2024-07-11 00:38:03       0 阅读
  3. js弹出对话框

    2024-07-11 00:38:03       0 阅读
  4. 优先级策略:在Eureka中配置服务实例优先级

    2024-07-11 00:38:03       0 阅读
  5. L298N的输出电流与电压

    2024-07-11 00:38:03       0 阅读
  6. 基于vite + pnpm monorepo 实现一个UI组件库

    2024-07-11 00:38:03       0 阅读

热门阅读

  1. Angular页面项目以HTTPS方式启动调试

    2024-07-11 00:38:03       9 阅读
  2. ArduPilot开源飞控之AP_VisualOdom

    2024-07-11 00:38:03       6 阅读
  3. 如何实现跨域

    2024-07-11 00:38:03       6 阅读
  4. centos7yum-mysql-community-server安装流程步骤

    2024-07-11 00:38:03       9 阅读
  5. toFixed 四舍五入问题

    2024-07-11 00:38:03       8 阅读
  6. [C++][CMake][嵌套的CMake]详细讲解

    2024-07-11 00:38:03       8 阅读
  7. 65.指针函数和函数指针

    2024-07-11 00:38:03       7 阅读
  8. 网络安全测评技术与标准

    2024-07-11 00:38:03       8 阅读
  9. Qt之多线程编程(QThread)

    2024-07-11 00:38:03       9 阅读
  10. MySQL:left join 后用 on 还是 where?

    2024-07-11 00:38:03       7 阅读
  11. 最短路径算法(算法篇)

    2024-07-11 00:38:03       10 阅读
  12. 【数学建模】生产企业原材料的订购与运输

    2024-07-11 00:38:03       7 阅读
  13. Spring Boot与Traefik的集成

    2024-07-11 00:38:03       9 阅读