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       45 阅读
  2. ELK的

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

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

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 00:38:03       6 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 00:38:03       5 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 00:38:03       4 阅读
  4. Python语言-面向对象

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

热门阅读

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

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

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

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

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

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

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

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

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

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

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

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

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

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