Subversion Repositories tpanel

Rev

Rev 305 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 305 Rev 306
Line 57... Line 57...
57
    TERRERROR,
57
    TERRERROR,
58
    TERRTRACE,
58
    TERRTRACE,
59
    TERRDEBUG
59
    TERRDEBUG
60
}terrtype_t;
60
}terrtype_t;
61
 
61
 
-
 
62
#ifdef __APPLE__
-
 
63
typedef uint64_t threadID_t;
-
 
64
#else
-
 
65
typedef std::thread::id threadID_t;
-
 
66
#endif
-
 
67
 
-
 
68
threadID_t _getThreadID();
62
std::ostream& indent(std::ostream& os);
69
std::ostream& indent(std::ostream& os);
63
void _msg(int lv, std::ostream& os);
70
void _msg(int lv, std::ostream& os);
64
void _lock();
71
void _lock();
65
void _unlock();
72
void _unlock();
66
 
73
 
Line 111... Line 118...
111
};
118
};
112
 
119
 
113
class TTracer
120
class TTracer
114
{
121
{
115
    public:
122
    public:
116
        TTracer(const std::string msg, int line, char *file, std::thread::id tid);
123
        TTracer(const std::string msg, int line, char *file, threadID_t tid);
117
        ~TTracer();
124
        ~TTracer();
118
 
125
 
119
    private:
126
    private:
120
        std::string mHeadMsg;
127
        std::string mHeadMsg;
121
        int mLine{0};
128
        int mLine{0};
122
        std::string mFile;
129
        std::string mFile;
123
        std::chrono::steady_clock::time_point mTimePoint;
130
        std::chrono::steady_clock::time_point mTimePoint;
124
        std::thread::id mThreadID{0};
131
        threadID_t mThreadID{0};
125
};
132
};
126
 
133
 
127
class TError : public std::ostream
134
class TError : public std::ostream
128
{
135
{
129
    public:
136
    public:
Line 136... Line 143...
136
        static terrtype_t getErrorType() { return mErrType; }
143
        static terrtype_t getErrorType() { return mErrType; }
137
        static void setErrorType(terrtype_t et) { mErrType = et; }
144
        static void setErrorType(terrtype_t et) { mErrType = et; }
138
        static std::ostream& append(int lv, std::ostream& os);
145
        static std::ostream& append(int lv, std::ostream& os);
139
        static std::string append(int lv);
146
        static std::string append(int lv);
140
        static TStreamError* Current();
147
        static TStreamError* Current();
141
        static TStreamError* Current(std::thread::id tid);
148
        static TStreamError* Current(threadID_t tid);
142
        static void clear() { mHaveError = false; msError.clear(); mErrType = TERRNONE; }
149
        static void clear() { mHaveError = false; msError.clear(); mErrType = TERRNONE; }
143
        static void logHex(char *str, size_t size);
150
        static void logHex(char *str, size_t size);
144
        const TError& operator=(const TError& ref);
151
        const TError& operator=(const TError& ref);
145
        static void displayMessage(const std::string& msg);
152
        static void displayMessage(const std::string& msg);
146
 
153
 
Line 154... Line 161...
154
 
161
 
155
        static std::string msError;
162
        static std::string msError;
156
        static bool mHaveError;
163
        static bool mHaveError;
157
        static terrtype_t mErrType;
164
        static terrtype_t mErrType;
158
        static TStreamError *mCurrent;
165
        static TStreamError *mCurrent;
159
        static std::thread::id mThreadID;
166
        static threadID_t mThreadID;
160
        std::string mHeadMsg;
167
        std::string mHeadMsg;
161
};
168
};
162
 
169
 
163
#define MSG_INFO(msg)       { if (TStreamError::checkFilter(HLOG_INFO)) { _lock(); *TError::Current(std::this_thread::get_id())->getStream() << TError::append(HLOG_INFO) << msg << std::endl; TStreamError::resetFlags(); _unlock(); }}
170
#define MSG_INFO(msg)       { if (TStreamError::checkFilter(HLOG_INFO)) { _lock(); *TError::Current(_getThreadID())->getStream() << TError::append(HLOG_INFO) << msg << std::endl; TStreamError::resetFlags(); _unlock(); }}
164
#define MSG_WARNING(msg)    { if (TStreamError::checkFilter(HLOG_WARNING)) { _lock(); *TError::Current(std::this_thread::get_id())->getStream() << TError::append(HLOG_WARNING) << msg << std::endl; TStreamError::resetFlags(); _unlock(); }}
171
#define MSG_WARNING(msg)    { if (TStreamError::checkFilter(HLOG_WARNING)) { _lock(); *TError::Current(_getThreadID())->getStream() << TError::append(HLOG_WARNING) << msg << std::endl; TStreamError::resetFlags(); _unlock(); }}
165
#define MSG_ERROR(msg)      { if (TStreamError::checkFilter(HLOG_ERROR)) { _lock(); *TError::Current(std::this_thread::get_id())->getStream() << TError::append(HLOG_ERROR) << msg << std::endl; TStreamError::resetFlags(); _unlock(); }}
172
#define MSG_ERROR(msg)      { if (TStreamError::checkFilter(HLOG_ERROR)) { _lock(); *TError::Current(_getThreadID())->getStream() << TError::append(HLOG_ERROR) << msg << std::endl; TStreamError::resetFlags(); _unlock(); }}
166
#define MSG_TRACE(msg)      { if (TStreamError::checkFilter(HLOG_TRACE)) { _lock(); *TError::Current(std::this_thread::get_id())->getStream() << TError::append(HLOG_TRACE) << msg << std::endl; TStreamError::resetFlags(); _unlock(); }}
173
#define MSG_TRACE(msg)      { if (TStreamError::checkFilter(HLOG_TRACE)) { _lock(); *TError::Current(_getThreadID())->getStream() << TError::append(HLOG_TRACE) << msg << std::endl; TStreamError::resetFlags(); _unlock(); }}
167
#define MSG_DEBUG(msg)      { if (TStreamError::checkFilter(HLOG_DEBUG)) { _lock(); *TError::Current(std::this_thread::get_id())->getStream() << TError::append(HLOG_DEBUG) << msg << std::endl; TStreamError::resetFlags(); _unlock(); }}
174
#define MSG_DEBUG(msg)      { if (TStreamError::checkFilter(HLOG_DEBUG)) { _lock(); *TError::Current(_getThreadID())->getStream() << TError::append(HLOG_DEBUG) << msg << std::endl; TStreamError::resetFlags(); _unlock(); }}
168
#define MSG_PROTOCOL(msg)   { if (TStreamError::checkFilter(HLOG_PROTOCOL)) { _lock(); *TError::Current(std::this_thread::get_id())->getStream() << TError::append(HLOG_PROTOCOL) << msg << std::endl; TStreamError::resetFlags(); _unlock(); }}
175
#define MSG_PROTOCOL(msg)   { if (TStreamError::checkFilter(HLOG_PROTOCOL)) { _lock(); *TError::Current(_getThreadID())->getStream() << TError::append(HLOG_PROTOCOL) << msg << std::endl; TStreamError::resetFlags(); _unlock(); }}
169
 
176
 
170
#define DECL_TRACER(msg)    TTracer _hidden_tracer(msg, __LINE__, (char *)__FILE__, std::this_thread::get_id());
177
#define DECL_TRACER(msg)    TTracer _hidden_tracer(msg, __LINE__, (char *)__FILE__, _getThreadID());
171
 
178
 
172
#define IS_LOG_INFO()       TStreamError::checkFilter(HLOG_INFO)
179
#define IS_LOG_INFO()       TStreamError::checkFilter(HLOG_INFO)
173
#define IS_LOG_WARNING()    TStreamError::checkFilter(HLOG_WARNING)
180
#define IS_LOG_WARNING()    TStreamError::checkFilter(HLOG_WARNING)
174
#define IS_LOG_ERROR()      TStreamError::checkFilter(HLOG_ERROR)
181
#define IS_LOG_ERROR()      TStreamError::checkFilter(HLOG_ERROR)
175
#define IS_LOG_TRACE()      TStreamError::checkFilter(HLOG_TRACE)
182
#define IS_LOG_TRACE()      TStreamError::checkFilter(HLOG_TRACE)