print() to console log with color
Xcode doesn't support console coloring since Xcode 8.
But Since Xcode is fully unicode compatible, you can use emojis instead! for example you can use You can use โ ๏ธ
for warning messages and ๐
for error messages. (like the Xcode itself)
Or simply use these note books as a color:
๐: error message๐: warning message๐: ok status message๐: action message๐: canceled status message๐: Or anything you like and want to recognize immediately by color
for example:
print("โ ๏ธ", "Touch is not disabled as expected")
๐ Bounes
Using this method will help you to find the logs in the source code as fast as โก๏ธ by a simple eye scan:
And you can search for them "๐ฑ๐" to let the Xcode take you there. Take a look at this result comparison:
Custom emoji search
vs
Word search
Adding to @Mojtaba's answer, you can use this for automating logging:
enum LogType: String{case errorcase warningcase successcase actioncase canceled}class Logger{ static func log(_ logType:LogType,_ message:String){ switch logType { case LogType.error: print("\n๐ Error: \(message)\n") case LogType.warning: print("\n๐ Warning: \(message)\n") case LogType.success: print("\n๐ Success: \(message)\n") case LogType.action: print("\n๐ Action: \(message)\n") case LogType.canceled: print("\n๐ Cancelled: \(message)\n") } }}
You can use it this way:
Logger.log(.error, "Invalid Credit Information")