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.
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.
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', ].
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.
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.
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")
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:
vs
Nowadays, Xcode debugging console doesn't support coloring.
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