Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print() to console log with color

The code is:

let redColor = "\u{001B}[0;31m" var message = "Some Message" print(redColor + message)  //This doesn't work print("\(redColor)\(message)") //This also doesn't work 

and the output would look like this:

[0;31mSome Message 

I've also read this post: Color ouput with Swift command line tool, and it doesn't seem to work.

I don't want to use libraries.

like image 668
Zonily Jame Avatar asked Nov 14 '16 07:11

Zonily Jame


People also ask

How do I print in color in console log?

To style the logs, you should place %c within the first argument of console. log(). It will pick up the next argument as a CSS style for the ā€œ%cā€ pattern argument text.

How do I add color to my console?

Passing the console CSS style as an Array And then you can use the join() method to turn the array style elements into a string. // 1. Pass the css styles in an array const styles = [ 'color: green', 'background: yellow', 'font-size: 30px', 'border: 1px solid red', 'text-shadow: 2px 2px black', 'padding: 10px', ].

How do I print a log in console?

log() You should use the console. log() method to print to console JavaScript. The JavaScript console log function is mainly used for code debugging as it makes the JavaScript print the output to the console.

How do I change the color of my console log in node?

Using control characters to color our output In this case, we want to change to the yellow character for our foreground, which has an ID of 33 in the ANSI color chart. By placing [33m after our initial control character, we switch the console output color to yellow.


2 Answers

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:

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

like image 161
Mojtaba Hosseini Avatar answered Sep 16 '22 15:09

Mojtaba Hosseini


Nowadays, Xcode debugging console doesn't support coloring.

like image 27
Danyl Avatar answered Sep 17 '22 15:09

Danyl