Skip to main content

A bullet-train style Python logging utils.

Project description

logging-bullet-train

A bullet-train style Python logging utility that enhances your logging output with colorful and emoji-enhanced messages for better readability and quicker debugging.

Features

  • Colorful Log Levels: Each log level is color-coded for immediate recognition.
  • Emoji Indicators: Visual emojis represent different log levels, making logs more intuitive.
  • ISO Datetime Formatting: Timestamps are formatted in ISO format for consistency.
  • Customizable: Easily configurable to fit your project's needs.
  • Supports Multiple Environments: Compatible with various environments and Python versions.

Installation

You can install logging-bullet-train using pip:

pip install logging-bullet-train

For development purposes, use Poetry to install all dependencies:

poetry install

Usage

Here's a simple example to get you started:

import logging

import logging_bullet_train

# Set up the logger
logger = logging_bullet_train.set_logger("my_logger", level=logging.DEBUG)

# Log messages with different severity levels
logger.debug("This is a debug message")     # 🔎 DEBUG
logger.info("This is an info message")      # 💡 INFO
logger.warning("This is a warning message") # ⭐ WARNING
logger.error("This is an error message")    # 🚨 ERROR
logger.critical("This is a critical message")  # 🔥 CRITICAL
logger.log(1, "notset message")             # 🔘 UNKNOWN

Sample Output:

2024-12-21T08:08:12+00:00  🔎 DEBUG      my_logger:12  This is a debug message
2024-12-21T08:08:12+00:00  💡 INFO       my_logger:13  This is an info message
2024-12-21T08:08:12+00:00  ⭐ WARNING    my_logger:14  This is a warning message
2024-12-21T08:08:12+00:00  🚨 ERROR      my_logger:15  This is an error message
2024-12-21T08:08:12+00:00  🔥 CRITICAL   my_logger:16  This is a critical message
2024-12-21T08:08:12+00:00  🔘 UNKNOWN    my_logger:17  notset message

Advanced Configuration

Selecting an Emoji Theme

By default, the logger uses a set of emojis defined in the default theme:

  • DEBUG: 🔎
  • INFO: 💡
  • WARNING: ⭐
  • ERROR: 🚨
  • CRITICAL: 🔥
  • UNKNOWN: 🔘

Additional themes such as fruit, weather, and night are available in the source code. To switch themes, you can modify the formatter to use a different emoji mapping. For example:

from logging_bullet_train import level_emoji_fruit, BulletTrainFormatter, set_logger

class FruitBulletTrainFormatter(BulletTrainFormatter):
    def format(self, record):
        # Override emoji selection to use fruit theme
        level = record.levelno
        emoji = level_emoji_fruit.get(level, level_emoji_fruit[logging_bullet_train.LOGGING_UNKNOWN])
        record.levelname = f"{emoji} {record.levelname}"
        return super().format(record)

# Set up the logger with the custom formatter
logger = logging.getLogger("fruit_logger")
handler = logging.StreamHandler()
handler.setFormatter(FruitBulletTrainFormatter())
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

logger.info("This info message uses fruit emojis")

Customizing Colors and Formatting

The logger supports customization of colors and formatting. You can adjust color schemes or extend the formatter to better suit your needs by modifying the color dictionaries or overriding the BulletTrainFormatter methods.

from logging_bullet_train import set_logger, wrap_text, Fore, Back

# Set up a custom logger
custom_logger = set_logger("custom_logger", level=logging.DEBUG)

# Use custom color styling in your messages if needed
message = wrap_text("Custom styled message", fg=Fore.CYAN, bg=Back.BLACK)
custom_logger.info(message)

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

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

Source Distribution

logging_bullet_train-0.2.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logging_bullet_train-0.2.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file logging_bullet_train-0.2.0.tar.gz.

File metadata

  • Download URL: logging_bullet_train-0.2.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.8 Darwin/24.1.0

File hashes

Hashes for logging_bullet_train-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c763fe6d35b16bf746a05231ed214bce9a6d536be2f469a11baa9004ea5ae1f3
MD5 c26b2c09d4979a5db9464d3165819902
BLAKE2b-256 73e3ba747b1e434f0f618537e304bcb6488ac545041107739a847fafd3d9e234

See more details on using hashes here.

File details

Details for the file logging_bullet_train-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for logging_bullet_train-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71dd959e1b873dc89f8dd871415f5d6f05ad5ccd434ffe94d13e2d2928103832
MD5 2d72601da82151beafbeb8f06459d6ff
BLAKE2b-256 a4fb0b0f6406e7484e3fa85e63d82248191ff6598d45d61d1e5a5257948e375b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page