How to redefine clog to tee to original clog and a log file?

前端 未结 4 669
鱼传尺愫
鱼传尺愫 2020-12-17 04:17

I saw a useful start here:

http://www.cs.technion.ac.il/~imaman/programs/teestream.html

And it works great to make a new stream which goes to both clog and a

4条回答
  •  生来不讨喜
    2020-12-17 05:07

    You don't want to do what your've trying to do because the 'tee' is not working at the rdbuf level. So setting the rdbuf to something else will not work, the output will only go to one stream.

    You need to follow there example:

    e.g.

    fstream clog_file(...);
    xstream clog_x(...);
    TeeStream clog(clog_file, clog_x);
    

    then use clog everywhere instead of your original clog.

提交回复
热议问题