• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: No longer use NSLog() in Xcode 4?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: No longer use NSLog() in Xcode 4?


  • Subject: Re: No longer use NSLog() in Xcode 4?
  • From: George Warner <email@hidden>
  • Date: Fri, 16 Sep 2011 09:32:15 -0700

On Thu, 15 Sep 2011 10:29:42 -0700, Matt Neuburg <email@hidden> wrote:
> On Thu, 15 Sep 2011 09:43:00 -0700, Jerry Krinock <email@hidden> said:
> I'm trying very hard to embrace change and get on board with Xcode 4.  The worst thing for me is the loss of User Scripts, in which I had keyboard shortcuts for adding and bulk-removing NSLog() statements in a flash.

> Back in one of those rambling Xcode 4 threads on July 24, Patrick William Walker wrote:
> "The new action triggers inside the debugger are pure freakin' gold.  I haven't used NSLog() in weeks now."
> I can't find any documentation on "action triggers".  I'd appreciate an explanation of what "action triggers" are, and how they obviate NSLog().  I hope they does not require running with breakpoints on.
> He's talking about a breakpoint that logs and continues. But, as you say, this requires that breakpoints be turned on. In early versions of Xcode 4 this feature was broken (it worked, but the interface claimed we were paused at the breakpoint), but it seems okay now.

> My favorite way to deal with NSLog, stolen from Jens Alfke, is to call MyLog instead, with a definition in the precompiled header like this:

>   #define MyLog if(0); else NSLog

> When it's time to stop logging, change the 0 to 1. So elegant. m.

This is what I use in my pre-compiled header:

#ifdef DEBUG
#define NSLogDebug(format, ...) \
NSLog(@"<%s:%d> %s, " format, \
strrchr("/" __FILE__, '/') + 1, __LINE__, __PRETTY_FUNCTION__, ## __VA_ARGS__)
#else
#define NSLogDebug(format, ...)
#endif

Then in the debug configuration define DEBUG:

GCC_PREPROCESSOR_DEFINITIONS = $(value) DEBUG=1

So without changing anything my release builds have all their NSLogDebug's no-op'd out. Plus the format, __VA_ARGS__ allow me to do things like:

- (void) windowWillClose: (NSNotification *) notification {
NSLogDebug(@"id:%@, notification: <%@>", [self uniqueID], notification);
.
.
.
} // windowWillClose:

Which logs:

2011-09-16 09:09:39.727 CSR Progress Meter[39032:707] <ProgressMeter.m:188> -[ProgressMeter windowWillClose:], id:SPM-39032-1, notification: <NSConcreteNotification 0x100345260 {name = NSWindowWillCloseNotification; object = <NSWindow: 0x10014ef90>}>

-- 
Enjoy,
George Warner, x4-0668
Schizophrenic Optimization Scientist
Apple Developer Technical Support (DTS)
eMail: <email@hidden>
iChat: <email@hidden>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: No longer use NSLog() in Xcode 4?
      • From: Gerd Knops <email@hidden>
  • Prev by Date: Re: weird message in gdb
  • Next by Date: Can't assign Xcode to be default app for .php files
  • Previous by thread: Re: No longer use NSLog() in Xcode 4?
  • Next by thread: Re: No longer use NSLog() in Xcode 4?
  • Index(es):
    • Date
    • Thread