RSS

XCode Feature Proposal: Linking NSLog to Code

If you’ve ever used NSLogs to help in your debug process, this description probably fits your process. You add a log statement in this code over here. You look further at the code and find that the problem is probably elsewhere, so you go down the chain of files and add more NSLogs. You do this for awhile, and you’ve built up a sometimes large list of NSLogs. And sometimes what you log might be equivalent to other messages. Now looking at your console logs, you see all the statements, and you don’t immediately know where those messages are originating from. This could also arise if you leave your log statements in and come back to the code 3 months later.

Your solution right now is to pop up the global search window, copy and paste part of the message in, and then track down which log statement that came from. This can amount to a lot of work after awhile.

Instead, I propose that the XCode team add a very small feature to NSLog and their console that hyperlinks the outputted NSLog message in the console to the file and line number where it was generated. It would be great for developers to have a quick link they can follow that shows exactly where their log statements are coming from.

The code to add this would be relatively minor. For instance, you only need to write a one line macro to fix NSLog.

#define NSLog2(...) NSLog([NSString stringWithFormat:@"<!%s,%s!> %@", __FILE__, __LINE__, [NSString stringWithFormat: __VA_ARGS__]])

A call to NSLog2 will simply call NSLog and prepend the file name and line number. For example:

NSLog2(@"Hello %i %@", 500, [NSArray arrayWithObject:@"hi"]);
/* Prints to console:
2009-10-22 17:27:30.809 Todos[22446:a0f] <!/Users/deb/repositories/todos/AppController.m,22!> Hello 500 (
    hi
)
*/

In XCode, they would need to add a bit of code to the console that would look for strings formatted like . Then, they can strip everything between from the console method. They would the generate a clickable link for the message that would open up that source file and position the cursor at the line number. Very simple and incredible useful.

Thoughts? Good or bad idea? Do you have a hack to implement this?

  • ashishy

    attorney search
    Welcome to LegalX Lawyer Directory
    Your trusted, comprehensive resource for locating lawyers and law firms nationwide that can help you with all your legal issues. Search more than 500,000 lawyer listings by geographic location and areas of expertise such as DUI, Divorce, Personal Injury, Criminal Law and More. Use our extensive Attorney Directory database to find an experienced Professional Fast.
    _________
    Ashish

    attorney search

  • http://www.air-jordan-19.com air jordan 19

    Well , the view of the passage is totally correct ,your details is really reasonable and you guy give us valuable informative post, I totally agree the standpoint of upstairs. I often surfing on this forum when I m free and I find there are so much good information we can learn in this forum!
    baby-namboos.com

  • Vanessadenvries

    Thanks for sharing. The view is indeed correct. Best Trein naar Londen

  • http://www.boots-stores.us uggs outlet

    Dior homme shoes
    I've been looking for a similar to this post. Not only extensively but also detailly. We can learn a lot from the post. I recommend to you , you can come communication in here. Let us grow up together.On the other hand ,I know some websites content is very well.you can go and see.Such as XXXXX

  • http://www.pickegg.com/wholesale/red-laser/ red laser

    One day she will understand you.

  • http://www.cozyfivefingersshoes.com five fingers shoes

    Love everything about it. I love to talk about it. I love to dream about it. I see the wonderful inspiring photos online and wish I can be the one taking it. yeah, that’s my ultimate dream.

  • http://www.mac-makeup-union.com mac makeup

    I was very fantastic why i not see your blog before i will come back.

  • http://www.jordanshoesforsales-us.com/ Jordan Retro Shoes On Sale

    The coup sudden, rapid process of people off guard. In an interview that many people have said, did not think to calm Bamako overnight turned into guns occupied the city.pingdeshijieluanle852.

« Inline SCM: A Proposal For A Better SVN or Git | App Releases: The Now & Flickpad »