我试图将一个简单的错误记录合并到我现有的应用程序中,目前它报告错误只是使用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;
}