Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Follow publication

Member-only story

Colored Logs for Python

Mike Huls
Geek Culture
Published in
3 min readJun 9, 2022

--

Adding some color to our console logs! (image by author)

Logging is an essential part of developing applications and lead to quick debugging and a broader understanding of what’s going on in your app. In this easy and short article we’re going to make our console logs a bit clearer by adding some color. Let’s code!

Preparations

We first need to install a package

pip install coloredlogs

Also make sure you understand the basics of logging and how to add a handler to your log with the article below:

Step 1: create a logger

Nothing new here: we just create a logger

We use the getLogger method so that we don’t use the root logger.

Step 2: coloredlogs

Here we install coloredlogs on our logger.

The last line makes sure that coloredlogs doesn’t pass our log events to the root logger. This prevents that we log every event double.

Step 3: creating a colored formatter

We want to add some style to our console outputs. We’ll define that here

--

--

Mike Huls
Mike Huls

Written by Mike Huls

I write about interesting programming-related things: techniques, system architecture, software design and how to apply them in the best way. — mikehuls.com

Write a response