Commit de552c87 by 刘帅

日志标准化

去掉内容中的换行、添加交易号字段
[时间] [级别] [订单号] [日志内容]
parent a7de2ce8
......@@ -44,13 +44,13 @@ typedef QVector<DestinationPtr> DestinationList;
static const char TraceString[] = "TRACE";
static const char DebugString[] = "DEBUG";
static const char InfoString[] = "INFO ";
static const char WarnString[] = "WARN ";
static const char InfoString[] = "INFO";
static const char WarnString[] = "WARN";
static const char ErrorString[] = "ERROR";
static const char FatalString[] = "FATAL";
// 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)
{
......@@ -217,9 +217,10 @@ Level Logger::loggingLevel() const
void Logger::Helper::writeToLog()
{
const char* const levelName = LevelToText(level);
const QString completeMessage(QString("%1 %2 %3")
.arg(levelName)
const QString completeMessage(QString("%1 %2 %3 %4")
.arg(QDateTime::currentDateTime().toString(fmtDateTime))
.arg(levelName)
.arg(trans_id)
.arg(buffer)
);
......
......@@ -66,7 +66,9 @@ public:
level(logLevel),
qtDebug(&buffer) {}
~Helper();
QDebug& stream(){ return qtDebug; }
QDebug& stream(QString _trans_id){
trans_id = _trans_id;
return qtDebug; }
private:
void writeToLog();
......@@ -74,6 +76,7 @@ public:
Level level;
QString buffer;
QDebug qtDebug;
QString trans_id;
};
private:
......@@ -94,24 +97,24 @@ private:
//! Logging macros: define QS_LOG_LINE_NUMBERS to get the file and line number
//! in the log output.
#ifndef QS_LOG_LINE_NUMBERS
#define QLOG_TRACE() \
#define QLOG_TRACE(TRANS_ID) \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::TraceLevel) {} \
else QsLogging::Logger::Helper(QsLogging::TraceLevel).stream()
#define QLOG_DEBUG() \
else QsLogging::Logger::Helper(QsLogging::TraceLevel).stream(TRANS_ID)
#define QLOG_DEBUG(TRANS_ID) \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::DebugLevel) {} \
else QsLogging::Logger::Helper(QsLogging::DebugLevel).stream()
#define QLOG_INFO() \
else QsLogging::Logger::Helper(QsLogging::DebugLevel).stream(TRANS_ID)
#define QLOG_INFO(TRANS_ID) \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::InfoLevel) {} \
else QsLogging::Logger::Helper(QsLogging::InfoLevel).stream()
#define QLOG_WARN() \
else QsLogging::Logger::Helper(QsLogging::InfoLevel).stream(TRANS_ID)
#define QLOG_WARN(TRANS_ID) \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::WarnLevel) {} \
else QsLogging::Logger::Helper(QsLogging::WarnLevel).stream()
#define QLOG_ERROR() \
else QsLogging::Logger::Helper(QsLogging::WarnLevel).stream(TRANS_ID)
#define QLOG_ERROR(TRANS_ID) \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::ErrorLevel) {} \
else QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream()
#define QLOG_FATAL() \
else QsLogging::Logger::Helper(QsLogging::ErrorLevel).stream(TRANS_ID)
#define QLOG_FATAL(TRANS_ID) \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::FatalLevel) {} \
else QsLogging::Logger::Helper(QsLogging::FatalLevel).stream()
else QsLogging::Logger::Helper(QsLogging::FatalLevel).stream(TRANS_ID)
#else
#define QLOG_TRACE() \
if (QsLogging::Logger::instance().loggingLevel() > QsLogging::TraceLevel) {} \
......
......@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
return 0;
}
InitLogger();
QLOG_INFO()<<"start FmclientUi...";
QLOG_INFO(DEFAULT_TRANS_ID)<<"start FmclientUi...";
Widget w;
scanner s;
QFmClient client;
......
......@@ -22,6 +22,7 @@
#define MAX_BUF_LEN 25600
#define MAX_REQ_COUNT 25600
#define ROLL_BACK_FILE_NAME "fmclient.rbk"
#define DEFAULT_TRANS_ID "invalid"
class QFmClient : public QThread
{
......@@ -117,6 +118,7 @@ public:
QString _refundTransId;
QString mTransId; //for log
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