print() to console log with color print() to console log with color swift swift

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:

Demo

And you can search for them "๐Ÿ“ฑ๐Ÿ‘" to let the Xcode take you there. Take a look at this result comparison:

Custom emoji search

emoji search

vs

Word search

word search


Nowadays, Xcode debugging console doesn't support coloring.


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")