Colorizing Xcode Logs to Improve Log Tracing
I made the most colorful Xcode log tool ever
As discussed before in a lot of developer forums, Xcode doesn’t support console coloring since Xcode 8. Because Apple has removed plug-ins from Xcode — the reason is security that Apple cares a lot — and has introduced Xcode extensions. And Xcode extensions are not providing any solution to colorize the terminal. In a short, there is no built-in support to achieve this at these days.
Having an Android developer experience in my career, I have used Android Studio a lot and still admire what IntelliJ is doing for developers. While I am tracing logs in my daily life as an iOS Developer, I do miss the few great features of IntelliJ. One of them is advanced logging, definitely.
Fortunately, Apple supports Unicode characters in Swift. So you can distinguish your logs with several emojis related to the type of the log. I was following this way but solution isn’t the best for readability.
So I thought to build a solution that reads the system logs, filtering the related apps, and displays them instantly.
Meet Logify
Logify is an easy-to-use and easy-to-implement CLI tool. The most important part is that Logify does not work if you are collecting logs with print(_:)
method. You must be logging in with OSLog
framework provided by Apple.
There are two types of logging. If your app supports iOS 14 below and probably does, you should use os_log
Using import os.log or OSLog
If you are following bests practices in bundle identifier, your identifiers like that com.company.product
or com.company.subdomain.product
.
In my example: com.github.furkankaplan.bispy
. You can split it two-part as subsystem and category are shown above. Just replace it with your bundle identifier.
Using Logger API
In case your minimum SDK is iOS 14 and higher, there is a more modern way in favor of Apple’s API improvement on OSLog, Logger
.
You may wonder why encode
extension was used in the two examples? Now, may want to see the request and response JSON outputs in your logs for bug tracking. For instance, your logs could have newline characters. System logs are not read line by line. Sometimes several log messages are combined and read within one line. So the parsing algorithm should know the answer to that question:
Is “\n” character is taking place in the log message or is it splitting several log messages?
This is why you must add the below extension for both solutions.
There are 4 types of messages: .default
, .info
, .error
and .fault
. You can change the colors for each type of message by forking the repository.
These are not built-in solution to change colors for types.
Here is the Logify Github Repository colorizing Xcode logs.
How to use Logify cli?
After setting up the application, open the terminal app. Run the below command:
curl -L https://raw.githubusercontent.com/furkankaplan/Logify/main/Logify --output Logify
After the download is finished, run the following command:
chmod +x Logify
As the last step, move the file to /usr/local/bin
mv Logify /usr/local/bin
Here we go!
You can also use log stream
shell command to view instant logs but Logify was created to colorize Xcode logs and improve readability.
Thanks for reading.
Want to Connect?Feel free to contact with me at Twitter @kaplan_dev.