iTerm2 – Colorize The Tailed Logs In ITerm2 Terminal3 min read


Coloured logs are very helpful especially when you are going to deploy your application in production. The moment when the live traffic is shifted to your servers and you sit there eagerly watching the logs roll off in speed, only one thing in your mind that no warnings and errors should go by unnoticed. This is the best situation where colors play an important role.

In this article, I’m going to show you a way by which you can grep the individual lines from the logs using regex pattern match and change the color of that line instantaneously.

Let’s get started…

ITerm2 Triggers

In iTerm, a trigger is an action that is performed when text matching any regular regex pattern is received in the terminal session.

So, you’ll be creating triggers for different regex patterns which are used in the logs. Usually, loggers in Java follow a pattern where for every error they print out “error” keyword in the logs and likewise “warn” for warning and “Fatal” if something terrible has happened 🙂

I will show you how to create triggers for the above keywords, you can modify the regex to match the keyword that is getting used in your application while printing logs.

iTerm2 - Go to preferences
Go to preferences

A dialog box will open.

Click on the “Profiles” tab and select “Advanced” at the right.

Navigate to triggers
Navigate to triggers

This is where you will find the option for editing the triggers. Click on the “edit” in the triggers section and create triggers as below.

Create triggers for error, warn and fatal
Create triggers for error, warn and fatal

I’ve created triggers for error, warn and fatal regex.

Once you have created the triggers, the next time your terminal shows up the word error, it will show that line as red.

Colored logs on the iTerm2 terminal
Colored logs on the iTerm2 terminal

Conclusion

This is a very cool feature offered by iTerm terminal. I use iTerm2 as my default terminal on mac. And always make sure you are using the coloured logs as it makes it so much easier to view and identify if something has gone wrong.


  • Article By: Varun Shrivastava

  • Varun Shrivastava is an innovative Full Stack Developer at ThoughtWorks with around 4 years of experience in building enterprise software systems in finance and retail domain. Experienced in design, development, and deployment of scalable software. He is a passionate blogger and loves to write about philosophy, programming, tech and relationships. This is his space, you can get in touch with him here anytime you want.