views:

72

answers:

2

I've read this question which advocates taking NSLog statements out of Release builds.

Is it acceptable to, instead of cluttering the main log up with junk, write it to Apple System Log instead, then it'd be hidden from the main log?

Or am I just overcomplicating things? Are there any instances where logging has been useful to you in pinpointing a bug in an app after release?

+2  A: 

There is also this question that asks about any performance advantage by taking the statements out. The jury looks to still be out on any hard numbers, but conventional wisdom says to remove them by making their inclusion conditional with a macro. You still get your debugging info, and the user gets an app free of clutter.

Philip Regan
+2  A: 

I find that log messages I add during development generally do one of three things:

  1. Aid in debugging and testing new, unfinished features and code paths
  2. Provide information about the normal operation of the program such as task completion and common error conditions (e.g. no internet connection).
  3. Provide detailed information about unusual or unexpected events, including error conditions that are dangerous or not specifically handled, software updates, and malformed data coming from a server connection or file

Messages in category one I usually remove when the feature is complete, messages in category two I filter out with a macro like the one in the linked question, and messages in category three I leave in the release.

Obviously the lines are blurry, but I think it comes down to respecting the log. If your application floods it with information that isn't useful, it could make it difficult to notice errors from other applications, and will be a (small) resource drain.

Using ASL functions to log messages with lower priorities like debug and info that won't be visible to most users is a great idea for messages that fall in a grey area.

Sidnicious
Messages in the third category should be alerts or presented errors, not log statements. How many of your users leave the Console running in case your application logs a failure there?
Peter Hosey
@Peter, I log errors and warnings so that our crash handler (or user feedback submission) can search for those logs via ASL and send them to us; user never has to open the console, but it's a lot easier than asking them to remember the wording of an error dialog!
Barry Wark
@Peter I agree. The log messages are to record information that wasn't appropriate or specific enough to present in the UI, or to record events that aren't important enough to tell the user about at the time they happen, but could be useful in finding the cause of an issue later on.
Sidnicious
Excellent discussion, chaps. I feared I was going a bit funny in the head, as I wanted to do what Barry is saying, but never heard anyone talk about it. Now I know it's a realistic option, I'll be looking into doing this.
John Gallagher