-2

I have a big project and there are many NSLog() calls. When something happens some NSLog() works, and I don't know which NSLog get called. How can I find a place where is NSLog() get called in class file?

My NSLog is like this: NSLog(@"%@", someArray);

and here's the log:

2013-04-23 20:43:38.257 myProj[2101:707] {
    id = 1;
    version = 1;
}

What does myProj[2101:707] mean here? Does it give me any information about NSLog function's location in class?

Shamsiddin Saidov
  • 2,281
  • 4
  • 23
  • 35

3 Answers3

6

You could try searching the project for the output.

For instance if the output is

This is my output with values 3.1415 and 1.2345.

press cmdshiftF and search for "This is my output with values"

You can also insert placeholders in the search term:

enter image description here

DrummerB
  • 39,814
  • 12
  • 105
  • 142
1

Convert all of your NSLog usage to DLog and then the log statements will print:

  1. The file name
  2. The method name
  3. The line number

Of every line that is output to the log. In this way you can immediately see where all logging is being done. DLog is a much better logging mechanism to use than NSLog and you should start using it in all your projects.

Define DLog in you pch file as:

#ifdef DEBUG
#   define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__,  ##__VA_ARGS__);
#else
#   define DLog(...)
#endif
Wain
  • 118,658
  • 15
  • 128
  • 151
0

You can use the function class_getName to get the class name of the object your log statement is placed and include the class name in NSLog().

Like this:

#import <objc/runtime.h>
…
NSLog("%@ Some Log Statement", class_getName([self class]));
Community
  • 1
  • 1
David
  • 3,392
  • 3
  • 36
  • 47
  • That's a good point for the future, but I guess OP has a hard time locating the right NSLog statement in the first place. – DrummerB Apr 23 '13 at 16:08