在iPhone应用程序中创建多个日志文件 [英] Creating multiple log files in iPhone app

查看:95
本文介绍了在iPhone应用程序中创建多个日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iPhone应用程序中创建两个日志文件。如果我使用freopen()将NSLog输出重定向到一个文件,那么所有日志语句都会进入一个提到的文件。
但是我想将一些日志语句放入一个文件中,而将一些日志语句放入不同的文件中。

任何想法,我该怎么办?

I want to create two log files in my iPhone application. If I redirect the NSLog output to a file using freopen(), then all the log statements will go into one mentioned files.
But I want to put some log statements into one file while some into different file.

Any idea, how can I do that?

推荐答案

最好的方法是将您自己的记录器类编写为您使用的替代品,而不是NSLog()。这样,您可以在运行时轻松确定应将哪些日志写入哪个文件。您的自定义类可以使用NLog()同时写入控制台。这似乎是最佳方法,因为 freopen()只是批量重定向所有日志输出。

The best approach would be to write your own logger class as a drop in replacement that you use instead of NSLog(). That way you can easily determine in run-time which logs should be written to which file. Your custom class can use NLog() to write to the console at the same time. This seems like the optimum approach, since freopen() simply bulk redirects all log output.

这篇关于在iPhone应用程序中创建多个日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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