66 lines
2.3 KiB
C++
66 lines
2.3 KiB
C++
#include "qtLogRediretor.h"
|
|
|
|
class qtRediretor;
|
|
qtRediretor* qtRediretor_Ptr = nullptr;
|
|
static void qtMessageHandler(QtMsgType type, const QMessageLogContext& context, const QString& msg) {
|
|
// 获取当前时间
|
|
//QString timeStamp = QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss");
|
|
// 构建日志输出字符串
|
|
|
|
//SAMPLE
|
|
//[2025-06-05 11:08:55] [Thread 6808] [debug] [QT][Hd_SocketModule_FinsTcp.cpp:307][bool __cdecl Hd_SocketModule_FinsTcp::writeData(class std::vector<class cv::Mat,class std::allocator<class cv::Mat> > &,class QByteArray &,class nlohmann::json_abi_v3_11_3::basic_json<class std::map,class std::vector,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,bool,__int64,unsigned __int64,double,class std::allocator,struct nlohmann::json_abi_v3_11_3::adl_serializer,class std::vector<unsigned char,class std::allocator<unsigned char> >,void> &)] [TCP] "write_short_D855_1"
|
|
//QString outputMessage = QString("[%1:%2][%3] %4")
|
|
// .arg(QFileInfo(context.file).fileName())
|
|
// .arg(context.line)
|
|
// .arg(context.function)
|
|
// .arg(msg);
|
|
//qtRediretor_Ptr->sendMsg(outputMessage);
|
|
|
|
//SAMPLE
|
|
//[2025-06-05 11:20:50] [Thread 29180] [debug] [QT][Hd_SocketModule_FinsTcp.cpp:307] [TCP] "write_short_D855_1"
|
|
QString outputMessage = QString("[%1:%2] %3")
|
|
.arg(QFileInfo(context.file).fileName().left(5))
|
|
.arg(context.line)
|
|
.arg(msg);
|
|
qtRediretor_Ptr->sendMsg(outputMessage);
|
|
|
|
|
|
|
|
|
|
|
|
//if (_logService != nullptr)
|
|
// _logService->qtLogger.LogDebug(outputMessage.toStdString());
|
|
//// 根据消息类型进行不同处理
|
|
//switch (type) {
|
|
//case QtDebugMsg:
|
|
// //// 打印到控制台
|
|
// //QTextStream(stdout) << outputMessage << endl;
|
|
|
|
// //// 也可以将日志写入文件
|
|
// //{
|
|
// // QFile file("debug_log.txt");
|
|
// // if (file.open(QIODevice::Append | QIODevice::Text)) {
|
|
// // QTextStream out(&file);
|
|
// // out << outputMessage << endl;
|
|
// // }
|
|
// //}
|
|
// break;
|
|
//case QtInfoMsg:
|
|
// // 可以扩展对信息类型的处理
|
|
// break;
|
|
//case QtWarningMsg:
|
|
// // 可以扩展对警告类型的处理
|
|
// break;
|
|
//case QtCriticalMsg:
|
|
// // 可以扩展对严重错误类型的处理
|
|
// break;
|
|
//case QtFatalMsg:
|
|
// // fatal消息会导致程序崩溃
|
|
// break;
|
|
//}
|
|
}
|
|
qtRediretor::qtRediretor()
|
|
{
|
|
qtRediretor_Ptr = this;
|
|
qInstallMessageHandler(qtMessageHandler);
|
|
}
|