我用宏在日誌機制工作的有線輸出:更大的宏觀結構
#define LOGFATAL 1 // very serious errors
#define TOSTRING(s) dynamic_cast< std::ostringstream & >((std::ostringstream() << s)).str()
#define LOG_TRANSFER(t, s) "[" << t << "] " << s
void inline print_log(const char *level, const std::string& value)
{
std::cout << "[" << timestamp() << "]["<< level << "]" << value << std::endl;
}
#ifdef DEBUGGING
#define DEBUG_OUT(l, s) print_log(l, TOSTRING(s));
#else
#define DEBUG_OUT(s, l)
#endif
#if DEBUGGING >= LOGFATAL
#define LOG_FATAL(s) DEBUG_OUT("FATAL", s)
#else
#define LOG_FATAL(s)
#endif
我用它自己的方式: LOG_TRACE(LOG_TRANSFER(PTR「的MemoryManager>分配 「)) LOG_TRACE(」的MemoryManager>尺寸:「< < active_list.size())
什麼GCC所做的是:
print_log("TRACE", dynamic_cast< std::ostringstream & >((std::ostringstream() << "[" << ptr << "] " << "MemoryManager > allocate ")).str());
print_log("TRACE", dynamic_cast< std::ostringstream & >((std::ostringstream() << "MemoryManager > size : " << active_list.size())).str());
這看起來不錯,但我得到以下輸出:
[0 s][TRACE]0x80940d40x9988ea8] MemoryManager > allocate
[0 s][TRACE]0x80941e01
錯誤在哪裏?
右值轉換的不錯解釋 - 當我自己遇到這個問題時,我還沒有意識到.flush()技巧來解決它。 – Pyrce