• 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
NSLog to a file?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSLog to a file?


  • Subject: NSLog to a file?
  • From: Angela Brett <email@hidden>
  • Date: Fri, 3 May 2002 18:12:27 +1200

Hi,

I'm sure this is an easy question - even I can think of a few approaches but I'd like some ideas on the best one.

I have a background app which has previously used NSLog to log information about what it's doing. I want to make it log to a file instead, for the release version anyway, so that it doesn't clutter the console and so that people can send me their logs if they have problems. I have replaced all calls to NSLog with ASLog, and for now I've just #defined ASLog to be NSLog.

I know I could do that by replacing the NSLog calls with something which creates an NSString using stringWithFormat, and passes that to my own log function to append the string to a file. But I would like to be able to leave the ASLog calls as they are. I've read the previous thread on removing NSLog calls for deployment, and discovered that I can't just make a macro to change ASLog(format,blah,blah,blah...) to ASLogString([NSString stringWithFormat: format,blah,blah,blah...]) because they don't support variable numbers of arguments.

I have read a bit about writing functions with variable numbers of arguments but I don't know how to just pass all the arguments into a method like stringWithFormat:.

My other thought was that maybe if I assigned a FILE * for the log file to stderr, then NSLog would write to that file. I haven't tried that yet, but I'm not sure if it's such a good idea to mix things like fopen() with other Cocoa code, especially after reading the thread abuot special characters in pathnames.

So, what would be the best way to go about this? I'm sure it must have been done before. Will I have to change all my ASLog calls or is there a way I can leave them as they are?
--
Angela Brett email@hidden http://acronyms.co.nz/angela
"Great minds think different."
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Follow-Ups:
    • Re: NSLog to a file?
      • From: Ondra Cada <email@hidden>
    • Re: NSLog to a file?
      • From: Malte Tancred <email@hidden>
    • Re: NSLog to a file?
      • From: Cryx <email@hidden>
  • Prev by Date: Re: NSTableView scrollbars won't activate
  • Next by Date: Re: NSLog to a file?
  • Previous by thread: Lossless PDF scaling
  • Next by thread: Re: NSLog to a file?
  • Index(es):
    • Date
    • Thread