Skip to main content

A simple logging package

Project description

log21

version stars forks repo size CodeFactor

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_print function, 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.

Issues contributors

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.3.0

Add log21.helper_types module.

This module contains a collection of useful types meant for using with argument parser to parse CLI arguments to more usable formats.

  • FileSize: Can take str and int values. Will convert human inputs such as "121 KB", "21MiB", or "4.56 GB" to bytes. Can also be used to represent bytes value in more human-readable formats.

For even more control you can still define Logger, Handlers, and Formatters manually.

Example

from pathlib import Path

import log21
from log21.helper_types import FileSize


def main(path: Path, min_size: FileSize, max_size: FileSize, /):
    log21.info(
        "Files that are smaller than %s or bigger than %s will be ignored.",
        args=(min_size, max_size),
    )

    for file in path.iterdir():
        if not file.is_file():
            continue
        if min_size <= (size := file.stat().st_size) <= max_size:
            log21.print(
                "`%s` is %s.",
                args=(file, FileSize(size).humanize(binary=False, fmt="%.4f")),
            )


if __name__ == "__main__":
    log21.argumentify(main)

Example usage and output:

$ uv run test.py . "1.23MiB" "0.5 GB"
[21:21:21] [INFO] Files that are smaller than 1.23 MiB or bigger than 476.84 MiB will be
ignored.
`myfile21.zip` is 35.1856 MB.

Full CHANGELOG

Usage Examples

See EXAMPLES.md

About

Author: CodeWriter21 (Mehrad Pooryoussof)

GitHub: MPCodeWriter21

Telegram Channel: @CodeWriter21

License

License

apache-2.0

Donate

In order to support this project you can donate some crypto of your choice 8D

Donate Addresses

Or if you can't, give this project a star on GitHub :)

References

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

log21-3.3.0.tar.gz (79.8 kB view details)

Uploaded Source

Built Distribution

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

log21-3.3.0-py3-none-any.whl (87.8 kB view details)

Uploaded Python 3

File details

Details for the file log21-3.3.0.tar.gz.

File metadata

  • Download URL: log21-3.3.0.tar.gz
  • Upload date:
  • Size: 79.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for log21-3.3.0.tar.gz
Algorithm Hash digest
SHA256 817b0c3356836eeb2b59680f1a8ec5443495e98ace83a862d8eed5990f427ce9
MD5 b9e8caa99a6587e286b749795a21c646
BLAKE2b-256 f708adeec7e4d75615491eb12236d66d448b3ea0a514990812eebdbc80c6b90e

See more details on using hashes here.

File details

Details for the file log21-3.3.0-py3-none-any.whl.

File metadata

  • Download URL: log21-3.3.0-py3-none-any.whl
  • Upload date:
  • Size: 87.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for log21-3.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 029a69a31e44365ffb764c91a812f3bb6f9a797dfb751e3c46ea2a08a92261bc
MD5 9f6c39f7195c60e7ec3128c1def63fb0
BLAKE2b-256 06a72e956ffc627c28698d516bb1d8f98f5c7633c5b7d4e7e1f25e8cd3c0231f

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