logging - How do you get the variables passed into function using macros (objective c) -



logging - How do you get the variables passed into function using macros (objective c) -

does know how dynamically variables values passed function sake of logging ?

i'm looking simple way (like using compiler macro) able log function, , variable values passed (which written log file can find inputs cause functions crash)

i've been trying

#define nfdebug( s, ... ) nslog( @"debug: %s: %@", __pretty_function__, \ [nsstring stringwithformat:(@"%@"), ##__va_args__] )

,which gives everything, variables values

i utilize this:

#ifdef your_debug_enabler_symbol_only_set_in_debug_builds #define debug_only(_code_) _code_ #else #define debug_only(_code_) #endif #define debuglog(_str, ...) debug_only(nslog(@"%s: " _str, __func__, ## __va_args__))

note there no comma before _str in nslog - means string utilize in calling code appended (by compiler) "%s: " string become composite format string nslog. whatever parameters want print can included in passed in format string. %s applies _ _ func _ _ , _str applies rest of passed in variables:

float f; int i; nsstring* s; // initialise f, i, , s ... // log values when in debug mode, function name auto-prepended debuglog(@"float is: %f - int is: %d - string is: %@", f, i, s);

this has advantage can log whatever text , variables want, conditionally on debug, , function name automatically prepended onto output.

objective-c logging macros nslog

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -