Swift stderr和stoutr合并为单个文件 [英] Swift stderr and stout into single file

查看:196
本文介绍了Swift stderr和stoutr合并为单个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于iPhone应用程序,我需要将调试数据收集到一个文件中,然后发送到在线服务进行分析.通过将stderr输出转移到文件句柄并在适当的时候发送文件,可以很好地工作. (NSLog输出也以stderr结尾,因此可以全面使用.)相同的方法对于stdout也可以正常工作.

For an iPhone app, I need to collect debugging data into a file to be sent to an online service for analysis. This works fine by diverting the stderr output to a file handle and sending the file when appropriate. (NSLog output also ends up in stderr, so this works across the board.) The same method also works fine with stdout.

这是我保存到文件的方法:

Here is how I do the saving to a file:

freopen(cStringFilePath, "a+", stderr) // or stdout

上面的代码正确地返回了UnsafeMutablePointer<FILE>,为了在必要时关闭文件,我会对其进行跟踪.

The above correctly returns a UnsafeMutablePointer<FILE> which I keep track of in order to close the file when necessary.

但是,我需要一个文件中的stdoutstderr的内容,并逐行正确地排列时间顺序.

However, I would need the content of both stdout and stderr in one file, with the correct time sequence line by line.

这样做的原因是我正在尝试调试第三方框架,该框架会生成诊断输出,但会将其写入stdout而不是stderr.

The reason for this is that I am trying to debug a third party framework which produces diagnostic output but writes it to stdout rather to stderr.

有什么想法要实现吗?

推荐答案

您是否尝试过两次调用freopen?一次使用stderr,一次使用stdout?我认为当我尝试时,此方法可以很好地达到我的目的.

Have you tried just calling freopen twice? Once with stderr and once with stdout? I think that worked fine for my purposes when I tried it.

这篇关于Swift stderr和stoutr合并为单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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