Skip to main content

Just another Colorful Logger with my personal customizations to be used in any python script.

Project description

Yet Another Colorful Logger

RELEASE NEW VERSION GitHub version PyPI version

Description

Yet Another Colorful Logger is just another Python logging utility that adds color to your console log messages. This module is already configured, not requiring any setup. Simply install it and integrate into your Python projects. However, if you want to customize it, you can do it as well.

For customizing the logger, you can change the colors, the format, and the log level. For more details, check the Customization section.

This module was created for personal use, but feel free to use it in your projects as well. Also, feel free to customize it according to your needs.

Any issues, suggestions, or questions, please feel free to reach out.

Installation

To install Yet Another Colorful Logger, use pip:

pip install yet-another-colorful-logger

Usage

To start using the logger is pretty forward. Just import it and create a logger instance:

from yaclogger import YACLogger

# Create a logger instance
logger = YACLogger(name="my_logger")

# Log messages with different severity levels
logger.debug("This is a debug message !!!")
logger.info("This is an info message !!!")
logger.warning("This is a warning message !!!")
logger.error("This is an error message !!!")
logger.critical("This is a critical message !!!")

Yet Another Colorful Logger Example

Customization

For customizing the colors, you can pass a dictionary as the log_colors parameter to the YACLogger constructor. The dictionary must contain the log level as the key and the color as value, both in strings. In case you want to use a background color, you can pass the color name with the prefix bg_, separated by a comma.

Example 1:

If you want to change the background only for the ERROR log level, you can pass the following dictionary:

my_custom_log_colors = {
    "ERROR": "black,bg_red"
}

yaclogger = YACLogger(name="my_logger", log_colors=my_custom_log_colors)

Example 2:

If you want to change the background only for DEBUG and CRITICAL log level, you can pass the following dictionary:

my_custom_log_colors = {
    "DEBUG": "green,bg_white",
    "CRITICAL": "red"
}

yaclogger = YACLogger(name="my_logger", log_colors=my_custom_log_colors)

Example 3:

If you want to change the color for all log levels, you can pass the following dictionary:

my_custom_log_colors = {
    "DEBUG": "light_blue",
    "INFO": "green",
    "WARNING": "cyan",
    "ERROR": "purple",
    "CRITICAL": "black,bg_white"
}
yaclogger = YACLogger(name="my_logger", log_colors=my_custom_log_colors)

Available Colors

black blue purple cyan
red white light_black light_red
green light_green light_yellow light_blue
yellow light_purple light_cyan light_white

Note: In some terminals, the foreground colors can have the same representation as the background colors, even both codes being different on the code. So, if you use the same color for both foreground and background in the same log level, you may not be able to see the message.

Colors Example

Contact

For any questions, suggestions, or issues, feel free to reach out:

License

This project is licensed under the GNU 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

yet_another_colorful_logger-1.1.2.tar.gz (43.3 kB view hashes)

Uploaded Source

Built Distribution

Supported by

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