문제

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