Commit de552c87 by 刘帅

日志标准化

去掉内容中的换行、添加交易号字段
[时间] [级别] [订单号] [日志内容]
parent a7de2ce8
...@@ -44,13 +44,13 @@ typedef QVector<DestinationPtr> DestinationList; ...@@ -44,13 +44,13 @@ typedef QVector<DestinationPtr> DestinationList;
static const char TraceString[] = "TRACE"; static const char TraceString[] = "TRACE";
static const char DebugString[] = "DEBUG"; static const char DebugString[] = "DEBUG";
static const char InfoString[] = "INFO "; static const char InfoString[] = "INFO";
static const char WarnString[] = "WARN "; static const char WarnString[] = "WARN";
static const char ErrorString[] = "ERROR"; static const char ErrorString[] = "ERROR";
static const char FatalString[] = "FATAL"; static const char FatalString[] = "FATAL";
// not using Qt::ISODate because we need the milliseconds too // not using Qt::ISODate because we need the milliseconds too
static const QString fmtDateTime("yyyy-MM-dd hh:mm:ss.zzz"); static const QString fmtDateTime("yyyy-MM-dd hh:mm:ss,zzz");
static const char* LevelToText(Level theLevel) static const char* LevelToText(Level theLevel)
{ {
...@@ -217,9 +217,10 @@ Level Logger::loggingLevel() const ...@@ -217,9 +217,10 @@ Level Logger::loggingLevel() const
void Logger::Helper::writeToLog() void Logger::Helper::writeToLog()
{ {
const char* const levelName = LevelToText(level); const char* const levelName = LevelToText(level);
const QString completeMessage(QString("%1 %2 %3") const QString completeMessage(QString("%1 %2 %3 %4")
.arg(levelName)
.arg(QDateTime::currentDateTime().toString(fmtDateTime)) .arg(QDateTime::currentDateTime().toString(fmtDateTime))
.arg(levelName)
.arg(trans_id)
.arg(buffer) .arg(buffer)
); );
......
...@@ -66,7 +66,9 @@ public: ...@@ -66,7 +66,9 @@ public:
level(logLevel), level(logLevel),
qtDebug(&buffer) {} qtDebug(&buffer) {}
~Helper(); ~Helper();
QDebug& stream(){ return qtDebug; } QDebug& stream(QString _trans_id){
trans_id = _trans_id;
return qtDebug; }
private: private:
void writeToLog(); void writeToLog();
...@@ -74,6 +76,7 @@ public: ...@@ -74,6 +76,7 @@ public:
Level level; Level level;
QString buffer; QString buffer;
QDebug qtDebug; QDebug qtDebug;
QString trans_id;
}; };
private: private:
...@@ -94,24 +97,24 @@ private: ...@@ -94,24 +97,24 @@ private:
//! Logging macros: define QS_LOG_LINE_NUMBERS to get the file and line number //! Logging macros: define QS_LOG_LINE_NUMBERS to get the file and line number
//! in the log output. //! in the log output.
#ifndef QS_LOG_LINE_NUMBERS #ifndef QS_LOG_LINE_NUMBERS
#define QLOG_TRACE() \ #define QLOG_TRACE(TRANS_ID) \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::TraceLevel) {} \ if (QsLogging::Logger::instance().loggingLevel() > QsLogging::TraceLevel) {} \
else QsLogging::Logger::Helper(QsLogging::TraceLevel).stream() else QsLogging::Logger::Helper(QsLogging::TraceLevel).stream(TRANS_ID)
#define QLOG_DEBUG() \ #define QLOG_DEBUG(TRANS_ID) \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::DebugLevel) {} \ if (QsLogging::Logger::instance().loggingLevel() > QsLogging::DebugLevel) {} \
else QsLogging::Logger::Helper(QsLogging::DebugLevel).stream() else QsLogging::Logger::Helper(QsLogging::DebugLevel).stream(TRANS_ID)
#define QLOG_INFO() \ #define QLOG_INFO(TRANS_ID) \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::InfoLevel) {} \ if (QsLogging::Logger::instance().loggingLevel() > QsLogging::InfoLevel) {} \
else QsLogging::Logger::Helper(QsLogging::InfoLevel).stream() else QsLogging::Logger::Helper(QsLogging::InfoLevel).stream(TRANS_ID)
#define QLOG_WARN() \ #define QLOG_WARN(TRANS_ID) \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::WarnLevel) {} \ if (QsLogging::Logger::instance().loggingLevel() > QsLogging::WarnLevel) {} \
else QsLogging::Logger::Helper(QsLogging::WarnLevel).stream() else QsLogging::Logger::Helper(QsLogging::WarnLevel).stream(TRANS_ID)
#define QLOG_ERROR() \ #define QLOG_ERROR(TRANS_ID) \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::ErrorLevel) {} \ if (QsLogging::Logger::instance().loggingLevel() > QsLogging::ErrorLevel) {} \
else QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream() else QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream(TRANS_ID)
#define QLOG_FATAL() \ #define QLOG_FATAL(TRANS_ID) \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::FatalLevel) {} \ if (QsLogging::Logger::instance().loggingLevel() > QsLogging::FatalLevel) {} \
else QsLogging::Logger::Helper(QsLogging::FatalLevel).stream() else QsLogging::Logger::Helper(QsLogging::FatalLevel).stream(TRANS_ID)
#else #else
#define QLOG_TRACE() \ #define QLOG_TRACE() \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::TraceLevel) {} \ if (QsLogging::Logger::instance().loggingLevel() > QsLogging::TraceLevel) {} \
......
...@@ -30,7 +30,7 @@ int main(int argc, char *argv[]) ...@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
InitLogger(); InitLogger();
QLOG_INFO()<<"start FmclientUi..."; QLOG_INFO(DEFAULT_TRANS_ID)<<"start FmclientUi...";
Widget w; Widget w;
scanner s; scanner s;
QFmClient client; QFmClient client;
......
...@@ -50,6 +50,7 @@ QFmClient::QFmClient(QObject *parent) : QThread(parent) ...@@ -50,6 +50,7 @@ QFmClient::QFmClient(QObject *parent) : QThread(parent)
{ {
_endflag = false; _endflag = false;
_fmMSS = 1024; _fmMSS = 1024;
mTransId = DEFAULT_TRANS_ID;
} }
bool QFmClient::Init(QString proxy_IP, unsigned short proxy_port, unsigned short listen_prot, unsigned short long_timeout, unsigned short short_timeout) bool QFmClient::Init(QString proxy_IP, unsigned short proxy_port, unsigned short listen_prot, unsigned short long_timeout, unsigned short short_timeout)
...@@ -65,7 +66,7 @@ bool QFmClient::Init(QString proxy_IP, unsigned short proxy_port, unsigned short ...@@ -65,7 +66,7 @@ bool QFmClient::Init(QString proxy_IP, unsigned short proxy_port, unsigned short
char clientVerInfo[32]; char clientVerInfo[32];
if(0 == cfgFile) if(0 == cfgFile)
{ {
QLOG_ERROR()<<"open cfg file failed!\r\n"; QLOG_ERROR(DEFAULT_TRANS_ID)<<"open cfg file failed!";
return false; return false;
} }
...@@ -172,12 +173,12 @@ bool QFmClient::WaitForConnectReqFromPos() ...@@ -172,12 +173,12 @@ bool QFmClient::WaitForConnectReqFromPos()
_acceptedSock = accept(_listenSock, (struct sockaddr *)(&c_add), &sin_size); _acceptedSock = accept(_listenSock, (struct sockaddr *)(&c_add), &sin_size);
if(-1 == _acceptedSock) if(-1 == _acceptedSock)
{ {
qDebug() << "accept socket fail!\r\n"; qDebug() << "accept socket fail!";
return false; return false;
} }
qDebug() << "accept ok, ZF Client get connection from POS!\r\n"; qDebug() << "accept ok, ZF Client get connection from POS!";
return true; return true;
} }
...@@ -301,7 +302,7 @@ char * QFmClient::DecodeRecvData(char * buf, int length, int * dLength) ...@@ -301,7 +302,7 @@ char * QFmClient::DecodeRecvData(char * buf, int length, int * dLength)
int QFmClient::WaitAndReadDataFromPos(int type, int flag) int QFmClient::WaitAndReadDataFromPos(int type, int flag)
{ {
qDebug() << "wait and receive data from POS...\r\n"; qDebug() << "wait and receive data from POS...";
_rcvLength = 0; _rcvLength = 0;
...@@ -314,9 +315,9 @@ int QFmClient::WaitAndReadDataFromPos(int type, int flag) ...@@ -314,9 +315,9 @@ int QFmClient::WaitAndReadDataFromPos(int type, int flag)
if (0 >= (recbytes = RecvSockData(_acceptedSock, _tempbuf, (MAX_BUF_LEN - 1)))) if (0 >= (recbytes = RecvSockData(_acceptedSock, _tempbuf, (MAX_BUF_LEN - 1))))
{ {
#ifdef WIN32 #ifdef WIN32
qDebug() << "recv() return : " << recbytes << ";error : " << WSAGetLastError() << ";\r\n"; qDebug() << "recv() return : " << recbytes << ";error : " << WSAGetLastError() << ";";
#endif #endif
qDebug() << "read data from socket " << _acceptedSock << " fail!\r\n"; qDebug() << "read data from socket " << _acceptedSock << " fail!";
return -1; return -1;
} }
...@@ -336,15 +337,15 @@ int QFmClient::WaitAndReadDataFromPos(int type, int flag) ...@@ -336,15 +337,15 @@ int QFmClient::WaitAndReadDataFromPos(int type, int flag)
if(1 == flag) if(1 == flag)
precvBuf = DecodeRecvData(_tempbuf, recbytes, &recbytes); precvBuf = DecodeRecvData(_tempbuf, recbytes, &recbytes);
qDebug() << "received data from pos " << _acceptedSock << " : \n" << precvBuf; qDebug() << "received data from pos " << _acceptedSock << " : " << precvBuf;
QLOG_INFO()<< "received data from pos " << _acceptedSock << " : \n" << precvBuf; QLOG_INFO(DEFAULT_TRANS_ID)<< "received data from pos " << _acceptedSock << " : " << precvBuf;
while(0 < recbytes) while(0 < recbytes)
{ {
finLen = CheckIsCompleteJsonData(&checkCount, precvBuf + prosLen); finLen = CheckIsCompleteJsonData(&checkCount, precvBuf + prosLen);
if (0 != checkCount || ((0 == checkCount) && ( '}' != precvBuf[ prosLen + finLen - 1])) || ((MAX_BUF_LEN - 1) < curPos + finLen)) if (0 != checkCount || ((0 == checkCount) && ( '}' != precvBuf[ prosLen + finLen - 1])) || ((MAX_BUF_LEN - 1) < curPos + finLen))
{ {
qDebug() << "checkCount out!\r\n"; qDebug() << "checkCount out!";
return -1; return -1;
} }
...@@ -396,7 +397,7 @@ int QFmClient::ProcessPosReqData(QJsonObject& object) ...@@ -396,7 +397,7 @@ int QFmClient::ProcessPosReqData(QJsonObject& object)
if(json_error.error != QJsonParseError::NoError || !doc.isObject()) if(json_error.error != QJsonParseError::NoError || !doc.isObject())
{ {
qDebug() << "error request json data!\r\n"; qDebug() << "error request json data!";
return -1; return -1;
} }
...@@ -423,6 +424,7 @@ int QFmClient::ProcessPosReqData(QJsonObject& object) ...@@ -423,6 +424,7 @@ int QFmClient::ProcessPosReqData(QJsonObject& object)
} }
} }
object["trans_id"] = trans_id; object["trans_id"] = trans_id;
mTransId = trans_id;
} }
qDebug()<<object; qDebug()<<object;
...@@ -450,7 +452,7 @@ int QFmClient::ProcessPosReqData(QJsonObject& object) ...@@ -450,7 +452,7 @@ int QFmClient::ProcessPosReqData(QJsonObject& object)
if(!object.contains("checkValue") || !object["checkValue"].isDouble()) if(!object.contains("checkValue") || !object["checkValue"].isDouble())
{ {
qDebug() << "checkValue failed!\r\n"; qDebug() << "checkValue failed!";
flag = -1; flag = -1;
break; break;
} }
...@@ -599,7 +601,7 @@ int QFmClient::SendCtrlInfo2Proxy() ...@@ -599,7 +601,7 @@ int QFmClient::SendCtrlInfo2Proxy()
if (sendRlt != MAX_CTRL_INFO_LEN) if (sendRlt != MAX_CTRL_INFO_LEN)
{ {
#ifdef WIN32 #ifdef WIN32
qDebug() << "recv() return : " << sendRlt << ";error : " << WSAGetLastError() << ";\r\n"; qDebug() << "recv() return : " << sendRlt << ";error : " << WSAGetLastError() << ";";
#endif #endif
return -1; return -1;
} }
...@@ -618,9 +620,9 @@ int QFmClient::RecvAndCheckDataFromSock(int sock, int flag, int type) //type = ...@@ -618,9 +620,9 @@ int QFmClient::RecvAndCheckDataFromSock(int sock, int flag, int type) //type =
if (0 >= (recbytes = RecvSockData(sock, _tempbuf, (MAX_BUF_LEN - 1)))) if (0 >= (recbytes = RecvSockData(sock, _tempbuf, (MAX_BUF_LEN - 1))))
{ {
#ifdef WIN32 #ifdef WIN32
qDebug() << "recv() return : " << recbytes << ";error : " << WSAGetLastError() << ";\r\n"; qDebug() << "recv() return : " << recbytes << ";error : " << WSAGetLastError() << ";";
#endif #endif
qDebug() << "read data from socket "<< sock <<" fail!\r\n"; qDebug() << "read data from socket "<< sock <<" fail!";
return -1; return -1;
} }
...@@ -642,8 +644,8 @@ int QFmClient::RecvAndCheckDataFromSock(int sock, int flag, int type) //type = ...@@ -642,8 +644,8 @@ int QFmClient::RecvAndCheckDataFromSock(int sock, int flag, int type) //type =
precvBuf = DecodeRecvData(_tempbuf, recbytes, &recbytes); precvBuf = DecodeRecvData(_tempbuf, recbytes, &recbytes);
} }
qDebug() << "received data from Proxy " << sock << " :\n " << precvBuf; qDebug() << "received data from Proxy " << sock << " : " << precvBuf;
QLOG_INFO() << "received data from Proxy " << sock << " :\n " << precvBuf; QLOG_INFO(DEFAULT_TRANS_ID) << "received data from Proxy " << sock << " : " << precvBuf;
while(0 < recbytes) while(0 < recbytes)
{ {
...@@ -651,7 +653,7 @@ int QFmClient::RecvAndCheckDataFromSock(int sock, int flag, int type) //type = ...@@ -651,7 +653,7 @@ int QFmClient::RecvAndCheckDataFromSock(int sock, int flag, int type) //type =
if (((0 == checkCount) && ( '}' != precvBuf[ prosLen + finLen - 1])) || ((MAX_BUF_LEN - 1) < curPos + finLen)) if (((0 == checkCount) && ( '}' != precvBuf[ prosLen + finLen - 1])) || ((MAX_BUF_LEN - 1) < curPos + finLen))
{ {
qDebug() << "checkCount out!\r\n"; qDebug() << "checkCount out!";
return -1; return -1;
} }
...@@ -699,28 +701,28 @@ int QFmClient::SendData2ZhProxyAndWaitRspData() ...@@ -699,28 +701,28 @@ int QFmClient::SendData2ZhProxyAndWaitRspData()
if (rlt != 0) if (rlt != 0)
{ {
#ifdef WIN32 #ifdef WIN32
qDebug() << "send data to ZhProxy return : " << rlt << ";error : " << WSAGetLastError() << ";\r\n"; qDebug() << "send data to ZhProxy return : " << rlt << ";error : " << WSAGetLastError() << ";";
QLOG_ERROR()<< "send data to ZhProxy return : " << rlt << ";error : " << WSAGetLastError() << ";\r\n"; QLOG_ERROR(mTransId)<< "send data to ZhProxy return : " << rlt << ";error : " << WSAGetLastError() << ";";
#endif #endif
qDebug() << "send data to ZhProxy failed!\r\n"; qDebug() << "send data to ZhProxy failed!";
return -1; return -1;
} }
qDebug() << "wait and receive data from ZH Proxy...\r\n"; qDebug() << "wait and receive data from ZH Proxy...";
#ifdef AES_ENCRYPT #ifdef AES_ENCRYPT
if( recvAESDataFromProxy(_zhProxySock, _recvbuf, MAX_BUF_LEN) != 0) if( recvAESDataFromProxy(_zhProxySock, _recvbuf, MAX_BUF_LEN) != 0)
{ {
qDebug() << "receive data or check data failed\r\n"; qDebug() << "receive data or check data failed";
QLOG_ERROR() << "receive data or check data failed\r\n"; QLOG_ERROR(mTransId) << "receive data or check data failed";
return -1; return -1;
} }
#else #else
if (0 != RecvAndCheckDataFromSock(_zhProxySock, _codeFlag,0)) if (0 != RecvAndCheckDataFromSock(_zhProxySock, _codeFlag,0))
{ {
qDebug() << "receive data or check data failed\r\n"; qDebug() << "receive data or check data failed";
QLOG_ERROR() << "receive data or check data failed\r\n"; QLOG_ERROR(mTransId) << "receive data or check data failed";
return -1; return -1;
} }
#endif #endif
...@@ -737,7 +739,7 @@ int QFmClient::CheckRecvedData() ...@@ -737,7 +739,7 @@ int QFmClient::CheckRecvedData()
if(json_error.error != QJsonParseError::NoError || !doc.isObject()) if(json_error.error != QJsonParseError::NoError || !doc.isObject())
{ {
qDebug() << "error request json data!\r\n"; qDebug() << "error request json data!";
return -1; return -1;
} }
...@@ -753,7 +755,7 @@ int QFmClient::CheckRecvedData() ...@@ -753,7 +755,7 @@ int QFmClient::CheckRecvedData()
if(file.open(QFile::WriteOnly)) if(file.open(QFile::WriteOnly))
{ {
QString PrintInfo = json["ext"].toObject()["print"].toString(); QString PrintInfo = json["ext"].toObject()["print"].toString();
QLOG_INFO() << "print:\r\n" <<PrintInfo << "\r\n"; QLOG_INFO(DEFAULT_TRANS_ID) << "print:" <<PrintInfo << "";
file.write(PrintInfo.toUtf8()); file.write(PrintInfo.toUtf8());
file.close(); file.close();
} }
...@@ -783,12 +785,12 @@ int QFmClient::ProcessZhProxyRspDataAndSend2Pos() ...@@ -783,12 +785,12 @@ int QFmClient::ProcessZhProxyRspDataAndSend2Pos()
if (rlt != length) if (rlt != length)
{ {
#ifdef WIN32 #ifdef WIN32
qDebug() << "send to pos return : " << rlt << ";error : " << WSAGetLastError() << ";\r\n"; qDebug() << "send to pos return : " << rlt << ";error : " << WSAGetLastError() << ";";
QLOG_ERROR()<< "send to pos return : " << rlt << ";error : " << WSAGetLastError() << ";\r\n"; QLOG_ERROR(mTransId)<< "send to pos return : " << rlt << ";error : " << WSAGetLastError() << ";";
#endif #endif
return -1; return -1;
} }
QLOG_INFO() <<"send to pos:\n"<<_recvbuf; QLOG_INFO(mTransId) <<"send to pos:"<<_recvbuf;
return 0; return 0;
} }
...@@ -813,7 +815,7 @@ void QFmClient::BackupPosReq(char * req) ...@@ -813,7 +815,7 @@ void QFmClient::BackupPosReq(char * req)
if(toSendLength == 0) if(toSendLength == 0)
{ {
OutputDebugStringA("encrpt failed!"); OutputDebugStringA("encrpt failed!");
QLOG_ERROR() << "encrpt failed!"; QLOG_ERROR(mTransId) << "encrpt failed!";
delete [] out; delete [] out;
return; return;
} }
...@@ -854,7 +856,7 @@ int QFmClient::sendAESData2Proxy(int sock, char *buf, int length) ...@@ -854,7 +856,7 @@ int QFmClient::sendAESData2Proxy(int sock, char *buf, int length)
if(toSendLength == 0) if(toSendLength == 0)
{ {
OutputDebugStringA("encrpt failed!"); OutputDebugStringA("encrpt failed!");
QLOG_ERROR() << "encrpt failed!"; QLOG_ERROR(DEFAULT_TRANS_ID) << "encrpt failed!";
delete [] out; delete [] out;
return -1; return -1;
} }
...@@ -873,7 +875,7 @@ int QFmClient::sendAESData2Proxy(int sock, char *buf, int length) ...@@ -873,7 +875,7 @@ int QFmClient::sendAESData2Proxy(int sock, char *buf, int length)
if(res == SOCKET_ERROR) if(res == SOCKET_ERROR)
{ {
int err = WSAGetLastError(); int err = WSAGetLastError();
QLOG_ERROR() << "send failed! code:%d" << err; QLOG_ERROR(DEFAULT_TRANS_ID) << "send failed! code:%d" << err;
rlt = -1; rlt = -1;
break; break;
} }
...@@ -882,7 +884,7 @@ int QFmClient::sendAESData2Proxy(int sock, char *buf, int length) ...@@ -882,7 +884,7 @@ int QFmClient::sendAESData2Proxy(int sock, char *buf, int length)
if(curSendLength != toSendLength) if(curSendLength != toSendLength)
{ {
rlt = -1; rlt = -1;
QLOG_ERROR() << ("cannot send all data!"); QLOG_ERROR(DEFAULT_TRANS_ID) << ("cannot send all data!");
} }
delete [] out; delete [] out;
return rlt; return rlt;
...@@ -1002,7 +1004,7 @@ void QFmClient::run() ...@@ -1002,7 +1004,7 @@ void QFmClient::run()
CloseSocket(&_acceptedSock); CloseSocket(&_acceptedSock);
CloseSocket(&_listenSock); CloseSocket(&_listenSock);
CheckRollBackData(); CheckRollBackData();
mTransId = DEFAULT_TRANS_ID;
if(!StartListenport()) if(!StartListenport())
{ {
qDebug() << "Start Listen port : " << _clientPort <<" failed"; qDebug() << "Start Listen port : " << _clientPort <<" failed";
...@@ -1014,7 +1016,7 @@ void QFmClient::run() ...@@ -1014,7 +1016,7 @@ void QFmClient::run()
do do
{ {
int rlt, needBackup; int rlt, needBackup;
mTransId = DEFAULT_TRANS_ID;
if (!WaitForConnectReqFromPos()) if (!WaitForConnectReqFromPos())
{ {
break; break;
...@@ -1061,7 +1063,7 @@ void QFmClient::run() ...@@ -1061,7 +1063,7 @@ void QFmClient::run()
evt.exec(); evt.exec();
object["fmId"] = _refundTransId; object["fmId"] = _refundTransId;
QLOG_ERROR() << "refund fmId: " << _refundTransId; QLOG_ERROR(mTransId) << "refund fmId: " << _refundTransId;
} }
if (!object.contains("station_id")) { if (!object.contains("station_id")) {
//! 给到客户的文档中, 缺少 station_id 字段 //! 给到客户的文档中, 缺少 station_id 字段
...@@ -1072,7 +1074,7 @@ void QFmClient::run() ...@@ -1072,7 +1074,7 @@ void QFmClient::run()
if (0 != Try2ConnectZhProxy()) if (0 != Try2ConnectZhProxy())
{ {
qDebug() << "connect to proxy failed"; qDebug() << "connect to proxy failed";
QLOG_ERROR() << "connect to proxy failed"; QLOG_ERROR(mTransId) << "connect to proxy failed";
CloseSocket(&_acceptedSock); CloseSocket(&_acceptedSock);
if(reqtype == 72 || reqtype == 101) if(reqtype == 72 || reqtype == 101)
{ {
...@@ -1096,7 +1098,7 @@ void QFmClient::run() ...@@ -1096,7 +1098,7 @@ void QFmClient::run()
QString temp = QString(QJsonDocument(object).toJson()); QString temp = QString(QJsonDocument(object).toJson());
temp = temp.simplified(); temp = temp.simplified();
strcpy(_sendbuf, temp.toStdString().c_str()); strcpy(_sendbuf, temp.toStdString().c_str());
QLOG_INFO()<<"send to ZhProxy:\n"<<_sendbuf; QLOG_INFO(mTransId)<<"send to ZhProxy:"<<_sendbuf;
rlt = SendData2ZhProxyAndWaitRspData(); rlt = SendData2ZhProxyAndWaitRspData();
...@@ -1129,14 +1131,14 @@ void QFmClient::run() ...@@ -1129,14 +1131,14 @@ void QFmClient::run()
}while(!isInterruptionRequested()); }while(!isInterruptionRequested());
qDebug() << "Exit FmclientUi!\r\n"; qDebug() << "Exit FmclientUi!";
OutputDebugString(L"Exit FmclientUi!\r\n"); OutputDebugString(L"Exit FmclientUi!");
#ifdef WIN32 #ifdef WIN32
WSACleanup(); WSACleanup();
#endif #endif
QLOG_INFO()<< "Exit FmclientUi!\r\n\n"; QLOG_INFO(DEFAULT_TRANS_ID)<< "Exit FmclientUi!";
} }
void QFmClient::quit() void QFmClient::quit()
...@@ -1195,7 +1197,7 @@ bool QFmClient::StartListenport() ...@@ -1195,7 +1197,7 @@ bool QFmClient::StartListenport()
} }
qDebug()<<"listen "<<_clientPort; qDebug()<<"listen "<<_clientPort;
QLOG_INFO()<<"listen at "<<_clientPort; QLOG_INFO(DEFAULT_TRANS_ID)<<"listen at "<<_clientPort;
return true; return true;
} }
...@@ -1211,8 +1213,8 @@ void QFmClient::CheckRollBackData() ...@@ -1211,8 +1213,8 @@ void QFmClient::CheckRollBackData()
return; return;
} }
qDebug() << "need to roll back data...\r\n"; qDebug() << "need to roll back data...";
QLOG_INFO() << "need to roll back data...\r\n"; QLOG_INFO(mTransId) << "need to roll back data...";
fseek(file, 0, SEEK_SET); fseek(file, 0, SEEK_SET);
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
...@@ -1226,7 +1228,7 @@ void QFmClient::CheckRollBackData() ...@@ -1226,7 +1228,7 @@ void QFmClient::CheckRollBackData()
if (1 != rlt || 0 >= readLen) if (1 != rlt || 0 >= readLen)
{ {
qDebug() << "roll back file error, file length error!\r\n"; qDebug() << "roll back file error, file length error!";
remove(filename.toStdString().c_str()); remove(filename.toStdString().c_str());
return ; return ;
} }
...@@ -1242,7 +1244,7 @@ void QFmClient::CheckRollBackData() ...@@ -1242,7 +1244,7 @@ void QFmClient::CheckRollBackData()
if(rlt == 0) if(rlt == 0)
{ {
OutputDebugStringA("decrypt failed!"); OutputDebugStringA("decrypt failed!");
QLOG_ERROR() << "decrypt failed!"; QLOG_ERROR(DEFAULT_TRANS_ID) << "decrypt failed!";
return; return;
} }
...@@ -1253,7 +1255,7 @@ void QFmClient::CheckRollBackData() ...@@ -1253,7 +1255,7 @@ void QFmClient::CheckRollBackData()
if(json_error.error != QJsonParseError::NoError || !doc.isObject()) if(json_error.error != QJsonParseError::NoError || !doc.isObject())
{ {
qDebug() << "error rbk json data!\r\n"; qDebug() << "error rbk json data!";
remove(filename.toStdString().c_str()); remove(filename.toStdString().c_str());
return ; return ;
} }
...@@ -1268,8 +1270,8 @@ void QFmClient::CheckRollBackData() ...@@ -1268,8 +1270,8 @@ void QFmClient::CheckRollBackData()
strcpy(_sendbuf, temp.toStdString().c_str()); strcpy(_sendbuf, temp.toStdString().c_str());
qDebug() << "rollback data:" << _sendbuf; qDebug() << "rollback data:" << _sendbuf;
qDebug() << "\r\n"; qDebug() << "";
QLOG_INFO() << "rollback data:" << _sendbuf << "\r\n"; QLOG_INFO(mTransId) << "rollback data:" << _sendbuf << "";
do do
{ {
...@@ -1277,33 +1279,33 @@ void QFmClient::CheckRollBackData() ...@@ -1277,33 +1279,33 @@ void QFmClient::CheckRollBackData()
if (0 != Try2ConnectZhProxy()) if (0 != Try2ConnectZhProxy())
{ {
qDebug() << "roll back data: connect ZH Proxy failed, will try after 5 seconds...\r\n"; qDebug() << "roll back data: connect ZH Proxy failed, will try after 5 seconds...";
QLOG_INFO() << "roll back data: connect ZH Proxy failed, will try after 5 seconds...\r\n"; QLOG_INFO(mTransId) << "roll back data: connect ZH Proxy failed, will try after 5 seconds...";
continue; continue;
} }
#ifndef AES_ENCRYPT #ifndef AES_ENCRYPT
if (0 != SendCtrlInfo2Proxy()) if (0 != SendCtrlInfo2Proxy())
{ {
qDebug() << "roll back data: send ctrl info 2 ZH Proxy failed, will try after 5 seconds...\r\n"; qDebug() << "roll back data: send ctrl info 2 ZH Proxy failed, will try after 5 seconds...";
QLOG_INFO() << "roll back data: send ctrl info 2 ZH Proxy failed, will try after 5 seconds...\r\n"; QLOG_INFO(mTransId) << "roll back data: send ctrl info 2 ZH Proxy failed, will try after 5 seconds...";
continue; continue;
} }
#endif #endif
if (0 != SendData2ZhProxyAndWaitRspData()) if (0 != SendData2ZhProxyAndWaitRspData())
{ {
qDebug() << "roll back data: send data to proxy fail, will try after 5 seconds...\r\n"; qDebug() << "roll back data: send data to proxy fail, will try after 5 seconds...";
QLOG_INFO() << "roll back data: send data to proxy fail, will try after 5 seconds...\r\n"; QLOG_INFO(mTransId) << "roll back data: send data to proxy fail, will try after 5 seconds...";
continue; continue;
} }
//对冲正结果进行判断 //对冲正结果进行判断
QByteArray recvdata(_recvbuf); QByteArray recvdata(_recvbuf);
QLOG_INFO() << "roll back reply: " << _recvbuf; QLOG_INFO(mTransId) << "roll back reply: " << _recvbuf;
QJsonParseError json_error; QJsonParseError json_error;
QJsonDocument doc = QJsonDocument::fromJson(recvdata, &json_error); QJsonDocument doc = QJsonDocument::fromJson(recvdata, &json_error);
if(json_error.error != QJsonParseError::NoError || !doc.isObject()) if(json_error.error != QJsonParseError::NoError || !doc.isObject())
{ {
qDebug() << "error request json data!\r\n"; qDebug() << "error request json data!";
continue; continue;
} }
QJsonObject object = doc.object(); QJsonObject object = doc.object();
...@@ -1314,8 +1316,8 @@ void QFmClient::CheckRollBackData() ...@@ -1314,8 +1316,8 @@ void QFmClient::CheckRollBackData()
} }
}while(1); }while(1);
qDebug() << "roll back ok!\r\n"; qDebug() << "roll back ok!";
QLOG_INFO() << "roll back ok!\r\n"; QLOG_INFO(mTransId) << "roll back ok!";
CloseSocket(&_zhProxySock); CloseSocket(&_zhProxySock);
remove(filename.toStdString().c_str()); remove(filename.toStdString().c_str());
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#define MAX_BUF_LEN 25600 #define MAX_BUF_LEN 25600
#define MAX_REQ_COUNT 25600 #define MAX_REQ_COUNT 25600
#define ROLL_BACK_FILE_NAME "fmclient.rbk" #define ROLL_BACK_FILE_NAME "fmclient.rbk"
#define DEFAULT_TRANS_ID "invalid"
class QFmClient : public QThread class QFmClient : public QThread
{ {
...@@ -117,6 +118,7 @@ public: ...@@ -117,6 +118,7 @@ public:
QString _refundTransId; QString _refundTransId;
QString mTransId; //for log
static unsigned int s_reqCount; static unsigned int s_reqCount;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment