• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Logging to text files
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Logging to text files (From: "Devraj Mukherjee" <email@hidden>)

  • Prev by Date: drag image for multi-cell selection
  • Next by Date: Re: Random numbers?
  • Previous by thread: Re: Logging to text files
  • Next by thread: Re: Logging to text files
  • Index(es):
    • Date
    • Thread