4

using iphone sdk 4.0 I want to remove the function name stuff from this macro but am struggling

#define LOG(fmt, ...) NSLog((@"%s " fmt), __PRETTY_FUNCTION__,##__VA_ARGS__)

i tried

#define LOG(fmt, ...) NSLog((@"%s " fmt), ##__VA_ARGS__)

but this results in a crash!!

I want to be able to log like this

LOG("text to log");
LOG("text to log with param %d", param); etc
Vladimir
  • 170,431
  • 36
  • 387
  • 313
tech74
  • 1,355
  • 3
  • 21
  • 35
  • Use these [here](http://stackoverflow.com/questions/969130/nslog-tips-and-tricks/969291#969291) – progrmr Jul 13 '10 at 13:24

3 Answers3

7

Why not simply like this ?

#define LOG(fmt, ...) NSLog(fmt, ##__VA_ARGS__)
ingh.am
  • 25,981
  • 43
  • 130
  • 177
rems4
  • 86
  • 1
1

I think you want this

#define Log(fmt, ...) NSLog(fmt, ##__VA_ARGS__);
Ian1971
  • 3,666
  • 7
  • 33
  • 61
  • already tried that,it doesn't work as i already have all my log statements LOG("some text"); ie without the @ – tech74 Jul 13 '10 at 12:23
0

You should wrap your log macro in a do{ }while(0); statement to avoid possibility of errors with if statements

see

do { ... } while (0) — what is it good for?

Community
  • 1
  • 1
gheese
  • 1,170
  • 1
  • 11
  • 17