我用宏在日志机制工作的有线输出:更大的宏观结构
#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