As we all know, logs are often helpful to pinpointing programs problems. It's nice to have a resuable log library so that we could put more effort to much nicer things.
#include <fstream>
#include <sstream>
#include <iostream>
#define Trace(msg) Logger().get() << msg;
class Logger{
public:
~Logger(){
oss_ << std::endl;
std::cerr << oss_.str();
}
std::ostringstream& get() { return oss_; }
private:
std::ostringstream oss_;
};
int magic()
{
return 89777;
}
int main()
{
Trace("start");
int mg = magic();
if(mg > 56)
{
Trace("mg: " << mg << " > 56");
}
Trace("exit");
return 0;
}
demo output:
start
mg: 89777 > 56
exit