堵塞的重点是什么? [英] What is the point of clog?

查看:75
本文介绍了堵塞的重点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想知道,木log的目的是什么?据我所知,clog与cerr相同,但具有缓冲功能,因此效率更高.通常stderr与stdout相同,因此clog与cout相同.这对我来说似乎很la脚,所以我认为我一定会误会它.如果我将日志消息发送到同一位置,而将错误消息发送到同一位置(也许在/var/log/messages中),那么我可能不会写太多消息(因此,使用non命令不会造成太多损失)缓冲的cerr).根据我的经验,我希望日志消息是最新的(非缓冲的),因此我可以帮助您查找崩溃(因此,我不想使用缓冲的木c).显然我应该一直使用cerr.

I've been wondering, what is the point of clog? As near as I can tell, clog is the same as cerr but with buffering so it is more efficient. Usually stderr is the same as stdout, so clog is the same as cout. This seems pretty lame to me, so I figure I must be misunderstanding it. If I have log messages going out to the same place I have error messages going out to (perhaps something in /var/log/messages), then I probably am not writing too much out (so there isn't much lost by using non-buffered cerr). In my experience, I want my log messages up to date (not buffered) so I can help find a crash (so I don't want to be using the buffered clog). Apparently I should always be using cerr.

我希望能够重定向程序内部的堵塞.重定向cerr很有用,这样当我调用库例程时,我可以控制cerr和clog的去向.一些编译器可以支持吗?我刚刚检查了DJGPP,并将stdout定义为FILE结构的地址,因此执行"stdout = freopen(...)"之类的操作是非法的.

I'd like to be able to redirect clog inside my program. It would be useful to redirect cerr so that when I call a library routine I can control where cerr and clog go to. Can some compilers support this? I just checked DJGPP and stdout is defined as the address of a FILE struct, so it is illegal to do something like "stdout = freopen(...)".

  • 是否可以重定向clog,cerr,cout,stdin,stdout和/或stderr?
  • clog和cerr之间唯一的区别是缓冲吗?
  • 我应如何实施(或找到)更强大的日志记录功能(请链接)?

推荐答案

是否可以重定向clog,cerr,cout,stdin,stdout和/或stderr?

Is it possible to redirect clog, cerr, cout, stdin, stdout, and/or stderr?

是的.您需要 rdbuf 函数.

Yes. You want the rdbuf function.

ofstream ofs("logfile");
cout.rdbuf(ofs.rdbuf());
cout << "Goes to file." << endl;

clog和cerr之间唯一的区别是缓冲吗?

Is the only difference between clog and cerr the buffering?

据我所知,是的.

这篇关于堵塞的重点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆