Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of the date and time that appears before every NSLog statement in the console

I use NSLog in my application. And I'd like to get rid of the annoying beginning of each string: "2009-07-01 21:11:06.508 MyApp[1191:207]".

Is there a way to do so? Probably another logging function?

Thanks.

like image 322
Ilya Suzdalnitski Avatar asked Jul 01 '09 17:07

Ilya Suzdalnitski


People also ask

Where does NSLog write to?

NSLog outputs messages to the Apple System Log facility or to the Console app (usually prefixed with the time and the process id). Many of the system frameworks use NSLog for logging exceptions and errors, but there is no requirement to restrict its usage to those purposes.


1 Answers

Read these:

  • https://github.com/davislg/QuietLog
  • https://web.archive.org/web/20140924195139/http://cocoaheads.byu.edu/wiki/different-nslog

It's a Github project called "QuietLog", originally from our CocoaHeads site, that explains how to create a QuietLog function that does what you're describing. It also shows how to wrap QuietLog into a macro called LocationLog so that it'll print out the file name and line number where you've got the log statement. I use it in all of my projects, and I don't lose stray "NSLog" statements anymore.

like image 58
Dave DeLong Avatar answered Sep 18 '22 12:09

Dave DeLong