A simple logging package
Project description
log21
A simple logging package that helps you log colorized messages in Windows console and other operating systems.
Features
- Colors : The main reason for this package was to log text in the Windows console with the support of ANSI colors.
- Argument parsing : log21's argument parser can be used like python's argparse, but it also colorizes the output.
- Logging : A similar logger to logging. Logger but with colorized output and other options such as levelname modifications. It can also decolorize the output if you want to log into a file.
- Pretty printing : Have you ever wanted to colorize the output of the pprint module? log21's pretty printer can do that.
- Tree printing : You can pass a dict or list to
log21.tree_printfunction, and it will print it in a tree-like structure. It's also colorized XD. - ProgressBar : log21's progress bar can be used to show progress of a process in a beautiful way.
- LoggingWindow : Helps you to log messages and debug your code in a window other than the console.
- CrashReporter : log21's crash reporter can be used to report crashes in different ways. You can use it to log crashes to console or files or use it to receive crash reports of your program through email. And you can also define your own crash reporter functions and use them instead!
- Argumentify : You can use the argumentify feature to decrease the number of lines you need to write to parse command-line arguments. It's colored by the way!
- Any idea? Feel free to open an issue or submit a pull request.
Installation
Well, this is a python package so the first thing you need is python.
If you don't have python installed, please visit Python.org and install the latest version of python.
Then you can install log21 using pip module:
python -m pip install log21 -U
Or you can clone the repository and run:
pip install .
Or let the pip get it using git:
pip install git+https://github.com/MPCodeWriter21/log21
Changelog
v3.1.0
Change the way argumentify handles function parameters to argument-parser arguments
conversion.
POSITIONAL_ONLYandVAR_POSITIONALparameters will be positional arguments.POSITIONAL_OR_KEYWORDandKEYWORD_ONLYparameters have flags assigned to them.POSITIONAL_OR_KEYWORDparameters will be required if at least oneKEYWORD_ONLYparameter is there, otherwise they are optional.VAR_KEYWORDparameters are still not supported.
Example 1
def main(path: Path, /, output: Path, *, verbose: bool = False):
"""Process a file.
:param path: The input file path
:param output: The output file
:param verbose: Write more logs to the standard output.
"""
...
if __name__ == "__main__":
argumentify(main)
The help looks like this:
usage: test.py [-h] --output OUTPUT [--verbose] path
Process a file.
positional arguments:
path The input file path
options:
-h, --help
show this help message and exit
--output OUTPUT, -o OUTPUT
The output file
--verbose, -v
Write more logs to the standard output.
Note that path and output are required.
Example 2
def main(output: Path, /, *inputs: Path):
"""Process multiple files into one.
:param output: The output file
:param inputs: The path to the input files
"""
# Since `inputs` is a VAR_POSITIONAL, while being a positional argument, it can have
# zero length which is in many cases not intended.
# You might want to add a check for its length and raise an ArgumentError if it does
# not match your needs
# Check if at least one input has been passed and mark the argument as required
# if len(inputs) < 1:
# raise RequiredArgumentError("inputs")
# Raise an error unless at least two inputs are present
if len(inputs) < 2:
raise ArgumentError(message="You need to pass at least two files as input.")
...
The help looks like this:
usage: test.py [-h] output [inputs ...]
Process multiple files into one.
positional arguments:
output The output file
inputs The path to the input files
options:
-h, --help
show this help message and exit
Example 3
def main(first_name: str, last_name: str, output: Path, verbose: bool = False):
"""Write a greeting message.
:param first_name: The first name of the user to greet (optional)
:param last_name: The last name of the user to greet (optional)
:param output: The output file (stdout if none is provided)
:param verbose: If provided, will write the debug logs to stdout
"""
...
if __name__ == "__main__":
argumentify(main)
The help looks like this:
usage: test.py [-h] [--first-name FIRST_NAME] [--last-name LAST_NAME] [--output OUTPUT]
[--verbose]
Write a greeting message.
options:
-h, --help
show this help message and exit
--first-name FIRST_NAME, -f FIRST_NAME
The first name of the user to greet (optional)
--last-name LAST_NAME, -l LAST_NAME
The last name of the user to greet (optional)
--output OUTPUT, -o OUTPUT
The output file (stdout if none is provided)
--verbose, -v
If provided, will write the debug logs to stdout
Note that all the options are optional and default to None. verbose is False by
default since a default value is provided for it in function definition.
Usage Examples
See EXAMPLES.md
About
Author: CodeWriter21 (Mehrad Pooryoussof)
GitHub: MPCodeWriter21
Telegram Channel: @CodeWriter21
License
Donate
In order to support this project you can donate some crypto of your choice 8D
Or if you can't, give this project a star on GitHub :)
References
- ANSI Color Codes (Wikipedia): https://en.wikipedia.org/wiki/ANSI_escape_code
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 log21-3.1.0.tar.gz.
File metadata
- Download URL: log21-3.1.0.tar.gz
- Upload date:
- Size: 78.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9ea4d792a48f32605f6888a6b84bc140a8e38fb7f3b637fbb1a1c74c2a73aca8
|
|
| MD5 |
143140e610d787b613e187d96cf7c1b7
|
|
| BLAKE2b-256 |
da6fd9075273b55710854fc124c30b51189dcfb22821b7781fd1e4fa0ff2cd6d
|
File details
Details for the file log21-3.1.0-py3-none-any.whl.
File metadata
- Download URL: log21-3.1.0-py3-none-any.whl
- Upload date:
- Size: 86.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dabdb26d907a6ca6da0d1492cc7707ff5fcf19b2be3d7fe621d96ec8622a954b
|
|
| MD5 |
64bca286c3ba2e080f939bb7bcd68cab
|
|
| BLAKE2b-256 |
e6b09f394fde0441a9deb40bb05a19474bd055a603110269c1e6488304b3bed8
|