Re: Logging to text files
Re: Logging to text files
- Subject: Re: Logging to text files
- From: email@hidden (Tom Marchand)
- Date: Thu, 05 Jul 2007 17:51:22 +0000
If you don't want to code this, you can achieve the same functionally at the command line:
Command 2</tmp/redirect.log
Of course this will only be useful in a development environment.
-------------- Original message ----------------------
From: "Tom Harrington" <email@hidden>
> 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
_______________________________________________
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