What is good practice for generating verbose output?

前端 未结 5 894
庸人自扰
庸人自扰 2021-02-19 03:49

what is good practice for generating verbose output? currently, i have a function

bool verbose;
int setVerbose(bool v)
{
    errormsg = \"\";
    verbose = v;
           


        
5条回答
  •  别跟我提以往
    2021-02-19 04:00

    int threshold = 3;
    class mystreambuf: public std::streambuf
    {
    };
    mystreambuf nostreambuf;
    std::ostream nocout(&nostreambuf);
    #define log(x) ((x >= threshold)? std::cout : nocout)
    
    int main()
    {
        log(1) << "No hello?" << std::endl;     // Not printed on console, too low log level.
        log(5) << "Hello world!" << std::endl;  // Will print.
        return 0;
    }
    

提交回复
热议问题