Skip to main content

Python logging instead of complicated print

Project description

Simple Logging Module

I've been using pythons built-in logging for my previous projects, but i discovered that it doesn't work as expected when running cronjobs in docker containers. The logger fails to write to the specified file because cronjobs operate in a limited environment with different permissions. They often capture standard output and error to a default file, usually cron.log in my case. While there might be ways to fix this, as a coder, it feels much better to write my own logging module; it would be a disgrace otherwise. So with this module, i can read the logs from cron.log since it uses print statements with logging formatting.

Install

Install the module with:

pip install printinglog

Usage

To start using printinglog, initialize the logger with:

from printinglog import Logger

logger = Logger()

logger.info("This is a INFO log")

You can also change how much detail you want to show in your log:

logger = Logger(format="simple")
logger.info("This is a INFO log")
>> INFO: This is a INFO log

logger = Logger(format="logging")
logger.info("This is a INFO log")
>> 2024-07-26 22:55:28 - INFO: This is a INFO log

logger = Logger(format="detailed")
logger.info("This is a INFO log")
>> 2024-07-26 22:55:28 @main - INFO: This is a INFO log

logger = Logger(format="long")
logger.info("This is a INFO log")
>> INFO: This is a INFO log
2024-07-26 22:55:28 @main<test_function> - INFO: This is a INFO log

To change the colors for each log type, you can also specify that:

default_colors = {
    "info": "green",
    "error": "red",
    "warning": "yellow",
    "debug": "blue",
}
logger = Logger(colorscheme=default_colors)

Colors to choose from:

  • black
  • red
  • green
  • yellow
  • blue
  • magneta
  • cyan
  • white

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

printinglog-0.0.1.tar.gz (3.6 kB view hashes)

Uploaded Source

Built Distribution

printinglog-0.0.1-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

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