From background of Objective C when I use NSLog()
it prefixes the text with the date time stamp, but when I use print()
on Swift it only prints the text
So it there is a way to make it print the time stamp as well, or am I doing some thing wrong?
In order to print logs, we use the NSLog method in Objective-C programming language which we have used right from the Hello World example. Now, when we compile and run the program, we will get the following result. 2013-09-16 00:32:50.888 demo[16669] Hello, World!
SwiftLog - A Logging API package for Swift The usage is really straightforward. First you have to import the Logging framework, then you create a logger and you use that logger instance to print out various log messages. import Logging let logger = Logger(label: "app-identifier") logger.info("Hello World!")
A timestamp is that which contain some characters that are in an encoded form which will contain any event, date or time etc. For more information, you can also go through from here.
Because print
is not NSLog
. It is as simple as that.
NSLog
is a logging tool in Foundation that writes to the Apple System Log facility which appears on the console.
print(…)
is a print function in the Swift Standard Library that writes to standard out, which appears on the console in debug sessions.
You could add Date()
to your print
parameter to print the current time and date. (Or Date().description(with: Locale.current)
to get it in your local time zone.)
Or you could just use NSLog
which is available in Swift too (if you import Foundation).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With