• 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
Macro to output an NSString containing function name, line number plus a string with a variable number of arguments?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Macro to output an NSString containing function name, line number plus a string with a variable number of arguments?


  • Subject: Macro to output an NSString containing function name, line number plus a string with a variable number of arguments?
  • From: Laurent Daudelin <email@hidden>
  • Date: Tue, 17 Apr 2012 15:21:55 -0700

Not really a direct Xcode question but since the compilers is barking at my current try to write this macro, I thought I should ask here.

Basically, I found numerous variations on how to use NSLog as a basis to output something to log while adding the __PRETTY_FUNCTION__ and __LINE__ macros but what I'd like to have is a macro that does the same, e.g. takes a string with a format and a variable number of arguments, add __PRETTY_FUNCTION__ and __LINE__ and return an NSString that can be written to a custom log file.

I don't want to redirect the output of the console to a custom log and I don't want to bring a whole framework or write a custom class for something that seems so trivial, unless it's really impossible.

So far, my latest try is this:

#define FileLog(format, ...) {\
return [NSString stringWithFormat:@"\n  %s [Line %d] \n       %@", __PRETTY_FUNCTION__, __LINE__, [NSString stringWithFormat:(format), ##__VA_ARGS__]];\
}

But at each place where I call this macro, the compiler complains with:

error: expected expression before '{' token

So, is there any way to write such macro?

Thanks in advance for any help!

-Laurent.
--
Laurent Daudelin
AIM/iChat/Skype:LaurentDaudelin 				http://www.nemesys-soft.com/
Logiciels Nemesys Software					email@hidden


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Macro to output an NSString containing function name, line number plus a string with a variable number of arguments?
      • From: Marco S Hyman <email@hidden>
  • Prev by Date: Re: Would you expect to see a warning about things that aren't supported in the deployment target OS?
  • Next by Date: Re: Macro to output an NSString containing function name, line number plus a string with a variable number of arguments?
  • Previous by thread: Re: Would you expect to see a warning about things that aren't supported in the deployment target OS?
  • Next by thread: Re: Macro to output an NSString containing function name, line number plus a string with a variable number of arguments?
  • Index(es):
    • Date
    • Thread