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

2
  • 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. Commented Mar 5, 2015 at 11:30
  • I just want to create my logs how I need it. The timestamp is mostly needless Commented Mar 5, 2015 at 12:28

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I NSLog simply on the main Thread?! Isn't it also synchronising it?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.