0

is it possible to get rid of the timestamp in NSLog()? I want to keep the NSLog functionality but have more simple outputs. println() is no option because of the behaviour with threads

Michael
  • 1,030
  • 14
  • 29
  • Not answer to your question, but why do you want to keep NSLog? If you push your app to the store with NSLogs, you will get ERROR logged, and if you want to keep it you are using it for your self and can ignore it. – Miknash Mar 05 '15 at 11:30
  • I just want to create my logs how I need it. The timestamp is mostly needless – Michael Mar 05 '15 at 12:28

1 Answers1

0

Deploy your own log based on println which uses GCD to ensure that it gets executed on the main thread, e.g.

func log(string: String)
{
    dispatch_async(dispatch_get_main_queue()) { println(string) }
} 

You can also disable this for release with a compiler flag, e.g. see Disabling NSLog For Production In Swift Project.

Community
  • 1
  • 1
Sebastian
  • 8,046
  • 2
  • 34
  • 58
  • I NSLog simply on the main Thread?! Isn't it also synchronising it? – Michael Mar 05 '15 at 12:30
  • AFAIK `NSLog` only ensures, that the output is written thread-safe to `stderr` (which is another difference to `println`). Or what do you mean by synchronising? If it shall block the caller until it is done, then use `dispatch_sync`. – Sebastian Mar 05 '15 at 13:26