質問

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?

役に立ちましたか?

解決

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

他のヒント

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top