Log (QT下的项目log解决方案)一

项目中的log输出(QT版)

这种重定向的log输出方法,一般的程序都能hold住,但在多线程并且数据收发速度非常快的socket编程中,会报错,博主能力有限,没找出错误,请高手指正。另本人找到了另一个版本的log网址:https://blog.youkuaiyun.com/vicky_white/article/details/103142113

项目中经常用到log的日志输出,记录下来,省的每次都写。话不多说,直接上代码。

mylog.h文件:

#ifndef MYLOG_H
#define MYLOG_H


void logInit();


#endif // MYLOG_H

mylog.cpp文件:

#include "mylog.h"
#include <QString>
#include <QLoggingCategory>
#include <QIODevice>
#include <QFile>
#include <QDir>
#include <QDebug>
#include <QDateTime>
#include <QMutex>
#include <QApplication>
#include <QRegExp>

static QString logDirectory;
static QString logFileName;
static QMutex mutex;
static QFile file;
static QTextStream textStream;

void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
    QString text;
    switch(type)
    {
    case QtDebugMsg:
        text = QString("[Debug]");
        b
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值