3

Say I have 10 different implementation files that are run in an chaotic order, and in each of them I have an NSLog(@"Log");, and when I run the program I will get 10 Log's to my console output, but how can I know which one was logged by which file? I'm searching for something like

`In someFile1.m: Log`
`In someFile3.m: Log`
`In someFile2.m: Log`
`...`

And so on and so forth. Is that possible?

nemesis
  • 1,349
  • 1
  • 15
  • 30

2 Answers2

4

You can use preprocessor macros for that, take a look at this example:

NSLog(@"In %s - %s:%d someObject=%@", __FILE__, __func__, __LINE__, someObject);

Here's what's available: https://developer.apple.com/library/ios/qa/qa1669/_index.html

ghstcode
  • 2,902
  • 1
  • 20
  • 30
2

You can use __FILE__ macro:

NSLog(@"%s",__FILE__ );

Which outputs filename:

2013-10-16 20:49:17.536 ABC[3637:a0b] /Users/who/where//DeviceViewController.m
stefanB
  • 77,323
  • 27
  • 116
  • 141