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;
......
...@@ -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