12

When we submit the application with NSLog statements,

What will be the effect of the statements? Will those still executes? If it executes will these logs stored somewhere as application logs / system logs? Can we see those? Is it connected to Apple crash reporting in iTunesConnect?

Please clarify my doubts.

Easwaramoorthy Kanagaraj
  • 3,925
  • 8
  • 36
  • 62

5 Answers5

9

Short answer :-

  1. Yes it executes in the production app
  2. NSLog just log to the console, i do not think it is stored in somewhere.
  3. We can only see in the console.
  4. When application crash NSLog does not print in the crash submission reports.
Amarnath Balasubramanian
  • 9,300
  • 8
  • 34
  • 62
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
6

NSLog calls can be left in production code. It will be logged in the system log. Applications which litter the system log are annoying, and is an unprofessional way. So try to use Macros in Logging such that you can remove log code execution in production

#define DEBUG_MODE

#ifdef DEBUG_MODE
    #define DebugLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
    #define DebugLog( s, ... ) 
#endif
Lithu T.V
  • 19,955
  • 12
  • 56
  • 101
  • 3
    Actually, you should have several log levels. It still makes sense to log warnings and errors in production. – Sulthan Nov 11 '13 at 11:16
  • 1
    removing all logs make it difficult to remove bugs and read reports but yeah nslog slows down the app as many user of SO have reported considerable speed improvements after removing logs – amar Nov 11 '13 at 11:22
  • Is Macros are less time consuming? – Easwaramoorthy Kanagaraj Nov 11 '13 at 11:32
  • 1
    Easwaramoorthy Kanagaraj macros replaces code during compiling stage. So you can replace NSLog with empty space using macros. http://stackoverflow.com/questions/12798582/remove-nslog-from-release-builds – GxocT Nov 11 '13 at 11:39
5

NSLog statements will stay in production. You can find them via Shift + CMD + 2 or:

Xcode > Windows > Organizer

if you have connected your device. Check the Console you can see them, so as other people who use the app.

enter image description here

pkamb
  • 33,281
  • 23
  • 160
  • 191
lxzhh
  • 416
  • 1
  • 3
  • 12
2

Yes the statement executes if you left it in release build.

So its a better practice to comment NSLog in release build or use DEBUG MODE as said by @Lithu T.V

By doing this the performance will become better. Because NSLog is pretty slow. NSLog will do two things 1) write log messages to Apple System Logging(ASL) 2) if the app runs in xcode it write to stderr too.

The main problem lays in the first one. In order to achieve thread safe, every time NSLog is called, it opens an connection to ASL facility, sends message, and closes the connection. The connection operation is very expensive. Another reason is that NSLog spends some time to get the timestamp to log.

UPDATE: Also I don't think there is any direct way to check the log from system, however there are some softwares that helps in viewing the console log. Following could help you in displaying the console log: http://support.apple.com/kb/DL1465

I have never tried it myself. So can't give you the surety.

Neha
  • 1,751
  • 14
  • 36
2

NSLog statements will be stored & executed in production if you are not going to remove them. Which is not a good practice. If affects the application performance.

There is a good tutorial on displaying the logs on MobileTuts+

Mobile Tuts Plus NSlog tutorial

Anyways, If you want to store it, You need to store it somewhere in document directory, But then also you would not be able to get the files from device application directory. For that you can upload it somewhere in webserver or something like that. Then you can access them.

Please let me know if any more doubts.

CRDave
  • 9,279
  • 5
  • 41
  • 59
iCreative
  • 1,499
  • 1
  • 9
  • 22
  • Is the statement you have mentioned about NSLog from apple. If so could you paste the link please. – Easwaramoorthy Kanagaraj Nov 11 '13 at 11:33
  • Nope. It is not from apple. But if you check to print some logs using NSLog in your console, It affects the performance of your app & if you want to check the NSLog of your app in device, Just open organizer tool of XCode & run your app downloaded from Appstore. You would be able to see all the NSLogs in device console.Hope it might clears your doubt. – iCreative Nov 11 '13 at 11:37