I am currently using the following DebugLog macro
#if defined(DEBUG) && defined(useDebugLogs)
#define DebugLog( s, ... ) NSLog( @"<%s:(%d)> %@", __PRETTY_FUNCTION__, __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define DebugLog( s, ... )
#endif
However, now with test flight allowing remote logging this is a little dated.
Basically what I want to do is add a switch in my settings.plist to allow the user to turn on remote logging.
I've come across this tutorial http://jomnius.blogspot.com/2011/09/how-to-do-dynamic-debug-logging-in.html
However, it's a very poor explanation and doesn't actually seem to work.
well, the best way IMO is to just always send the logs and tweak your implementation so you see exactly what you want. you either want analytics, or you won't use them. there is an error, or there is not. work your way through them and improve your signal to noise ratio. anyways…
you could just create a dedicated function for this purpose. it can conditionally log or not based on some variable in your implementation. note that you may forward your va_list by calling NSLogv
rather than NSLog
, or you may use -[NSString initWithFormat:arguments:]
to forward the message + arguments elsewhere:
MONDebugLog.h
extern void MONDebugLog(NSString * format, ... ) NS_FORMAT_FUNCTION(1,2);
MONDebugLog.m
void MONDebugLog(NSString * format, ... ) {
enum {
MONLog_Undefined,
MONLog_Enable,
MONLog_Disable
};
static int DoLog = MONLog_Undefined;
if (MONLog_Undefined == DoLog) {
DoLog = ...load from plist or defaults and set to Log_Enable or Log_Disable...;
}
if (MONLog_Disable == DoLog) {
return;
}
va_list arguments;
va_start(arguments, format);
NSString * str = [[NSString alloc] initWithFormat:format arguments:arguments];
va_end(arguments);
...now log or xmit str...
}