Re: Logging to text files
Re: Logging to text files
- Subject: Re: Logging to text files
- From: "Tom Harrington" <email@hidden>
- Date: Thu, 5 Jul 2007 11:22:23 -0600
On 7/5/07, Devraj Mukherjee <email@hidden> wrote:
Hi everyone,
Can NSLog be used to write a Log file?
Yes-- with a little setup. NSLog writes to stderr, so if you redirect
stderr, you redirect NSLog.
The basic setup is:
FILE *newStderr = freopen("/tmp/redirect.log", "a", stderr);
NSLog(@"Test NSLog");
You should probably call umask() before redirecting with whatever mask
you want. The above will redirect all NSLog calls. If you wanted to
later restore normal NSLog behavior, a little work with dup() and
dup2() would do the trick of saving and restoring the file handle.
--
Tom Harrington
email@hidden
AIM: atomicbird1
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden