2

I have the following log outputs in Xcode:

2013-05-20 17:23:19.901 MyApp[2408:303] invalid pixel format
2013-05-20 17:23:19.901 MyApp[2408:303] invalid context

The problem is I don't know what line of code is generating these errors. I've tried walking through but it's extremely tedious considering the complexity of this part of my app. Is there a quick and simple way to track down the line of code that is outputting these?

0

2 Answers 2

5

Yes, there is a way to do what you are asking. Simply add the following to your prefix header YourAppName-Prefix.pch.

#define NSLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);

That will override NSLog with a custom NSLog that will print like this:

2013-05-20 21:11:10.407 YourAppName[46526:c07] -[JFDepthView initWithGestureRecognizer:] [Line 81] JFDepthView Initialized!

It should also work for 3rd party libraries you've added to your project.

Sign up to request clarification or add additional context in comments.

1 Comment

For me, adding this macro causes the build error Expected ')' to match this '(' in line 422 of NSObjCRuntime.h, where the NSLog function is declared. Am I doing something wrong?
2

From "C" documentation, Standard Predefined Macros - The C Preprocessor:

__FILE__ and __LINE__ are useful in generating an error message

NSLog(@"Line: %d", __LINE__);

5 Comments

I'm not the one outputting the logs above with NSLog()... it's a generated error by the compiler/Xcode when the app is running. I need to know where it's generated.
@EthanAllen Neither Xcode or the compiler are outputting those messages. They would be generated by whatever library or framework they are coming from.
OK, that makes sense, but how do I know which library? And what line of code called into it? I'm only calling into Apple libraries.
@Ethan, have you tried symbolic breakpoints? I don't know whether it would work because I've never tried it, but its what I would look into.
@HM If breakpoints were not ruled put a symbolic breakpoint with a condition should work well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.