Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 250 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to print out the method name and line number and conditionally disable NSLog?

#11
My answer to [this question][1] might help, looks like it's similar to the one Diederik cooked up. You may also want to replace the call to `NSLog()` with a static instance of your own custom logging class, that way you can add a priority flag for debug/warning/error messages, send messages to a file or database as well as the console, or pretty much whatever else you can think of.

#define DEBUG_MODE

#ifdef DEBUG_MODE
#define DebugLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self,
[[NSString stringWithUTF8String:__FILE__] lastPathComponent],
__LINE__,
[NSString stringWithFormat:(s),
##__VA_ARGS__] )
#else
#define DebugLog( s, ... )
#endif

[1]:

[To see links please register here]

Reply

#12
***It is simple,for Example***

> -(void)applicationWillEnterForeground:(UIApplication *)application {
>
>
> NSLog(@"%s", __PRETTY_FUNCTION__);
>
> }

**Output:**
-[AppDelegate applicationWillEnterForeground:]







Reply

#13
I've taken `DLog` and `ALog` from above, and added `ULog` which raises a `UIAlertView` message.

To summarize:


- `DLog` will output like `NSLog` only when the DEBUG variable is set
- `ALog` will always output like `NSLog`
- `ULog` will show the `UIAlertView` only when the DEBUG variable is set
<br/>
<pre>
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#ifdef DEBUG
# define ULog(fmt, ...) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
#else
# define ULog(...)
#endif
</pre>

This is what it looks like:



![Debug UIAlertView][1]

+1 Diederik

[1]:

Reply

#14
Disabling all NSLogs, for somebody allergic to MACROS, here is something that you can compile too:

void SJLog(NSString *format,...)
{
if(LOG)
{
va_list args;
va_start(args,format);
NSLogv(format, args);
va_end(args);
}
}

And, use it almost like NSLog:

SJLog(@"bye bye NSLogs !");

From this blog:

[To see links please register here]


Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through