Skip to main content

My logging improvement

Project description



Improved version of the standard logger.

  • Added TRACE level.
  • Added ColorizedFormatter.
  • Added better traceback formatting.

This package patching the standard logging library.

Thus, after import, all improvements will be available inside the logging module.

But for better typing, I prefer to use betterlogging everywhere.


Python 3.6 and above. No any additional dependencies.


pip install betterlogging


In code

import betterlogging as logging

# You can use shortcut:
logger = logging.get_colorized_logger(name="test")

# Or, if you want to configure formatter:
handler = logging.StreamHandler()


logger.trace("some trace message")
logger.debug("some debug message")"some info message")
logger.warning("some warning message")
logger.error("some error message")
logger.critical("some critical message")

def div(x: int, y: int) -> float:
    return x / y

    div(1, 0)
    logger.exception("Some exception")

Config for uvicorn

  "version": 1,
  "disable_existing_loggers": false,
  "formatters": {
    "default": {
      "()": "betterlogging.ColorizedFormatter"
    "access": {
      "()": "betterlogging.ColorizedFormatter",
      "fmt": "%(c_fg_green)s%(asctime)s %(c_color)s%(levelname)-8s%(c_reset)s %(c_fg_cyan)s[%(name)s] %(c_reset)s%(message)s"
  "handlers": {
    "default": {
      "formatter": "default",
      "class": "logging.StreamHandler"
    "access": {
      "formatter": "access",
      "class": "logging.StreamHandler",
      "stream": "ext://sys.stdout"
  "loggers": {
    "": {
      "handlers": [
      "level": "DEBUG"
    "uvicorn.error": {
      "level": "INFO"
    "uvicorn.access": {
      "handlers": [
      "level": "INFO",
      "propagate": false
uvicorn application:app --debug --reload --log-config ./logging.json

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for betterlogging, version 0.0.8
Filename, size File type Python version Upload date Hashes
Filename, size betterlogging-0.0.8-py3-none-any.whl (10.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size betterlogging-0.0.8.tar.gz (9.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page