Objective-C Language Logging Logging NSLog meta data


Example

NSLog(@"%s %d %s, yourVariable: %@", __FILE__, __LINE__, __PRETTY_FUNCTION__, yourVariable);

Will log the file, line number and function data along with any variables you want to log. This can make the log lines much longer, particularly with verbose file and method names, however it can help to speed up error diagnostics.

You can also wrap this in a Macro (store this in a Singleton or where you'll need it most);

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

Then when you want to log, simply call

ALog(@"name: %@", firstName);

Which will give you something like;

 -[AppDelegate application:didFinishLaunchingWithOptions:] [Line 27] name: John