I’m writing an Objective-C library and I’d like it to offer a simple pluggable logging mechanism, so that the library user can turn the logging on and off. I thought an interesting way to do this would be a block property on the library classes:
typedef void (^Logger)(NSString *fmt, ...);
@property(copy) Logger logger;
logger(@"Foo, %@.", self);
But I don’t know how to pass the variable argument list to NSLog:
const Logger SimpleLogger = ^(NSString *fmt, ...) {
// what goes in here?
};
Ah, I completely missed NSLogv:
const Logger SimpleLogger = ^(NSString *fmt, ...) {
va_list arglist;
va_start(arglist, fmt);
NSLogv(fmt, arglist);
va_end(arglist);
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With