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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file printinglog-0.0.1.tar.gz.
File metadata
- Download URL: printinglog-0.0.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b238fbec7460df6991a2218b0f9505476b4ef2eaa24e987c668dc1fe930053bd
|
|
| MD5 |
35c74459903b4ca7c95be852dffed8c8
|
|
| BLAKE2b-256 |
6ecb9fc9b9d4baa7a7d9c0c578c23a2c85ff12f7a412cf1dd3596e3e379430bd
|
File details
Details for the file printinglog-0.0.1-py3-none-any.whl.
File metadata
- Download URL: printinglog-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
558bdb47225c42d898f5fdf8bf04f4120f9ead51e8fe9af548c07b3187b8f41e
|
|
| MD5 |
958bf5cefac8058d807ccb847aeb92b7
|
|
| BLAKE2b-256 |
e00c75b39a6e44757f3692733987f6a6f2b11b0b7d0774663d8c0b160e67959a
|