Macro to output an NSString containing function name, line number plus a string with a variable number of arguments?
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