Skip to content
Muslu Yüksektepe

colorlg

A lightweight, dependency-free Python logger that colors terminal logs and filters out unwanted records.

colorlg is a lightweight logging library built on Python's own logging module that makes terminal output colorful and easy to read. It shows each log level in a different color and can filter out noisy log records coming from specific files. It has no external dependencies. I published it on PyPI in March 2026; the current version is 1.0.2.

Purpose

In my projects I always use a logger instead of print(). Python's default log output is a single color, though, so in a fast-scrolling terminal it is very easy to miss error and warning lines. On top of that, some libraries I use produce a lot of log records about their own internals, and those records drown out my application's messages. I wrote colorlg to solve both problems. Rather than copying the same formatter and filter code into every project, I wanted the same setup with a one-line import.

How it works

At the heart of the library are two classes and a setup function. ColorFormatter is a formatter derived from Python's logging.Formatter class. It writes each log record as fixed-width columns made of a timestamp, level, file name, line number and message. The level gets 8 characters, the file name 35 and the line number 5, so lines stacked on top of each other line up neatly. The whole line is colored with an ANSI color code based on its level. DEBUG shows in cyan, INFO in green, WARNING in yellow, ERROR in red and CRITICAL in magenta. ANSI color codes are special character sequences that tell the terminal what color to show text in.

ExcludeClientPyFilter is a filter derived from the logging.Filter class. It drops records that come from the files in the list of file names it is given. If no list is given, it blocks records from _client.py by default.

The setup_logger function brings these two pieces together. It takes the log level, the files to filter, whether to use color and which stream to write to as parameters. If color is turned off, the same column layout is used without color. When the library is imported, a ready-to-use logger object set up with this function is created as well.

Key features

  • After the line from colorlg import logger, you can start writing colored logs without any configuration.
  • Thanks to fixed-width columns, the time, level, file and line information stay aligned on every line.
  • Records from unwanted files can be silenced by passing a list.
  • Color can be turned off, so the same layout is kept when logs are written to a file or to an environment without color support.
  • Because the formatter and the filter are separate classes, anyone who wants only one of them in their own logging setup can add just that one.

Technical stack

colorlg uses only the Python standard library and needs nothing beyond the logging and datetime modules. The package is built with setuptools through pyproject.toml, supports Python 3.7 and later, and is distributed under the MIT license. pytest, black, flake8 and mypy are defined as optional development extras, but they are not part of a normal install. The default logger is created under its own name and does not pass its records on to parent loggers, which prevents the same message from being printed twice.

Use cases

  • I use it in command-line tools and background services to spot errors and warnings at a glance.
  • I silence chatty libraries, such as HTTP clients, by file name so my own application's messages stand out.
  • Using the same log format across several projects makes reading and comparing logs easier.
  • It is a short, clear example for showing people learning Python how to write a formatter and a filter with the logging module.
Category
Python libraries
Year
2026

Technologies

  • Python
  • PyPI
  • Logging

Links

  • PyPI https://pypi.org/project/colorlg/

Back to all projects