【发布时间】:2010-10-11 22:47:46
【问题描述】:
我试图将一个简单的错误日志记录合并到我现有的应用程序中,目前它只使用cout 报告错误,所以我希望使用<< 运算符保持类似的界面。但是我希望它记录发生错误的行和函数,但我不想每次需要记录时都输入__LINE__, __FUNCTION__。有谁知道我可以用来允许__LINE__ 宏在另一个函数中使用的技巧,而不是报告调用行?希望这是有道理的。
class myLogClass {
uint8_t level;
public:
bool operator<<( const char * input );
};
bool myLogClass::operator<<( const char * input ) {
logItInSQL( input );
return true;
}
不是每次都这样
myLogClass << "Line No: " << __LINE__
<< " Function: " << __FUNCTION__
<< " Error: " << "This is my error to be logged";
我希望能够做到:
myLogClass << "This is my error to be logged";
bool myLogClass::operator<<( const char * input ) {
logItInSQL( " Line No: __LINE__" );
logItInSQL( " Function: __FUNCTION__" );
logItInSQL( " Error: " + input );
return true;
}
【问题讨论】:
标签: c++ logging c-preprocessor