免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2024 | 回复: 5
打印 上一主题 下一主题

[Linux] linux下面的fd, 能否区分log stream和标准错误stream? [复制链接]

论坛徽章:
2
2015年迎新春徽章
日期:2015-03-04 10:16:532015元宵节徽章
日期:2015-03-06 15:53:22
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2015-11-09 10:13 |只看该作者 |倒序浏览
我在linux下做c++的开发,尝试着看一下cerr和clog这两个东西的区别。
我写了一个简单的测试程序,发现clog是和cerr一样,绑定在2号描述符上面的:当我把2>/dev/null重定向了以后,发现cerr和clog同时都没有了。

问题来了,如果看clog的说明,似乎不是绑定在cerr/cout上面的,而是依赖于系统的logging stream实现。

所以我的疑问是: linux系统下面是否有相关的设定来制定log输出到哪里?
----------------------------------------------------------------
The global objects std::clog and std::wclog control output to a stream buffer of implementation-defined type (derived from std::streambuf), associated with the standard C output stream stderr, but, unlike std::cerr/std::wcerr, these streams are not automatically flushed and not automatically tie()'d with cout.
These objects are guaranteed to be initialized during or before the first time an object of type std::ios_base::Init is constructed and are available for use in the constructors and destructors of static objects (as long as <iostream> is included).
Unless sync_with_stdio(false) has been issued, it is safe to concurrently access these objects from multiple threads for both formatted and unformatted output.

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
2 [报告]
发表于 2015-11-09 13:37 |只看该作者
0 1 2 三个是进程生成,自动打开占用的;

你可以再进程里面重定向;把你的 log 绑定到 3 自己写log函数

看看 APUE 相关章节获得更多信息

论坛徽章:
2
2015年迎新春徽章
日期:2015-03-04 10:16:532015元宵节徽章
日期:2015-03-06 15:53:22
3 [报告]
发表于 2015-11-10 13:57 |只看该作者
yjh777 发表于 2015-11-09 13:37
0 1 2 三个是进程生成,自动打开占用的;

你可以再进程里面重定向;把你的 log 绑定到 3 自己写log函数
...


哪个章节提到了"把你的 log 绑定到 3 自己写log函数"如何做呢?
还请指点,谢谢。

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
4 [报告]
发表于 2015-11-10 16:15 |只看该作者
哈哈,没有章节提把 log 绑定,,,

我的意思是你看看 APUE 先理解: 文件描述符 、stdin stdout stderr 等等概念 之后
    你就不会再问这些问题了,因为你已经知道问题的原因和怎么解决问题了。

论坛徽章:
2
2015年迎新春徽章
日期:2015-03-04 10:16:532015元宵节徽章
日期:2015-03-06 15:53:22
5 [报告]
发表于 2015-11-12 14:22 |只看该作者
yjh777 发表于 2015-11-10 16:15
哈哈,没有章节提把 log 绑定,,,

我的意思是你看看 APUE 先理解: 文件描述符 、stdin stdout stderr  ...


谢谢,我知道文件描述符的含义,然后我想知道这个log本身是不是已经对应了某个系统默认的描述符数字了。
如果没有的话,clog就是绑定到cerr上面啊,那我有cerr就可以了,干嘛还弄个clog呢?
谢谢。

论坛徽章:
84
每日论坛发贴之星
日期:2015-12-29 06:20:00每日论坛发贴之星
日期:2016-01-16 06:20:00每周论坛发贴之星
日期:2016-01-17 22:22:00程序设计版块每日发帖之星
日期:2016-01-20 06:20:00每日论坛发贴之星
日期:2016-01-20 06:20:00程序设计版块每日发帖之星
日期:2016-01-21 06:20:00每日论坛发贴之星
日期:2016-01-21 06:20:00程序设计版块每日发帖之星
日期:2016-01-23 06:20:00程序设计版块每日发帖之星
日期:2016-01-31 06:20:00数据库技术版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-16 06:20:00程序设计版块每日发帖之星
日期:2016-01-14 06:20:00
6 [报告]
发表于 2015-11-12 18:34 |只看该作者
回复 5# cdsfiui

系统默认只打开三个 0 stdin 1 stdout 2 stderr
  没听说有默认绑定log的,  不排除有什么库会这么做,,,
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP