print() to console log with color
Nowadays, Xcode debugging console doesn't support coloring.
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")
ð Bones
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 error
case warning
case success
case action
case 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")