Simpler NSLog macro
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
Why not simply like this ?
#define LOG(fmt, ...) NSLog(fmt, ##__VA_ARGS__)
I think you want this
#define Log(fmt, ...) NSLog(fmt, ##__VA_ARGS__);
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?
精彩评论