Skip to main content

log21

version pipeline status repo size

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 merge 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://gitlab.com/CodeWriter21/log21.git

Changelog

v3.3.2

Handle percent signs in arguments' help text.

In the older versions, if you had a percent sign in the help text of an argument, it would cause an error when you try to show the help. This is because the argparse module uses percent signs for string formatting, and it would try to format the help text as a string, which would fail if there are any percent signs in it.

The workaround for this issue was to escape the percent signs by doubling them, but it was not a good solution. Now, in v3.3.2, log21 handles percent signs in arguments' help text properly, so you can use percent signs without any issues.

Example (works before and after v3.3.2)

import log21


def show_percentage(a: float, b: float, /) -> None:
    """Takes two numbers and returns the percentage of a in b. E.g. if a is 50 and b is
    200, the percentage would be 25.00%.

    :param a: The first number. (a %% b)
    :param b: The second number. (a %% b)
    :return: The percentage of a in b.
    """
    if b == 0:
        raise log21.ArgumentError("b cannot be zero.")
    percentage = (a / b) * 100
    print(f"{a} is {percentage:.2f}% of {b}.")


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

Example (Works only after v3.3.2)

import log21


def show_percentage(a: float, b: float, /) -> None:
    """Takes two numbers and returns the percentage of a in b. E.g. if a is 50 and b is
    200, the percentage would be 25.00%.

    :param a: The first number. (a % b)
    :param b: The second number. (a % b)
    :return: The percentage of a in b.
    """
    if b == 0:
        raise log21.ArgumentError("b cannot be zero.")
    percentage = (a / b) * 100
    print(f"{a} is {percentage:.2f}% of {b}.")


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

Full CHANGELOG

Usage Examples

See EXAMPLES.md

About

Author: CodeWriter21 (Mehrad Pooryoussof)

GitLab: CodeWriter21

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 GitLab :)

References

Release files for log21 3.3.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for log21 3.3.3
File Size Uploaded
log21-3.3.3.tar.gz 79.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for log21 3.3.3
File Interpreter ABI Platform
log21-3.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 167.9 kB

Release files / log21-3.3.3.tar.gz

Download URL log21-3.3.3.tar.gz
Size 79.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1a92d7878449422bfb1d036c46181c60fa4d0d2cdc18cd1c817fab5ed718d5e2
BLAKE2b-256 checksum
How to use checksums
919b84940b374ad314d57b8073d05fa865b1f39050a17eb48ce697ef09926bae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / log21-3.3.3-py3-none-any.whl

Download URL log21-3.3.3-py3-none-any.whl
Size 88.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cef983cb4f827c368e6a90fcee2e2efc39a67dca8df47abf9c675773408866f1
BLAKE2b-256 checksum
How to use checksums
264daf16694135a3804a7ab0087b3be1ac4d2eab2f7ab1fea2a0d4592818a4af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.30 {"installer":{"name":"uv","version":"0.9.30","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

3.12.2

2 release files

3.12.1

2 release files

3.12.0

2 release files

3.11.0

2 release files

3.10.3

2 release files

3.10.2

2 release files

3.9.0

2 release files

3.8.0

2 release files

3.7.1

2 release files

3.7.0

2 release files

3.6.0

2 release files

3.5.0

2 release files

3.4.0

2 release files

This release

3.3.3 This release

2 release files

3.3.2

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.10.0

2 release files

2.9.2

2 release files

2.9.1

2 release files

2.9.0

2 release files

2.8.1

2 release files

2.8.0

2 release files

2.7.1

2 release files

2.7.0

2 release files

2.6.2

2 release files

2.6.1

2 release files

2.6.0

2 release files

2.5.4

2 release files

2.5.3

2 release files

2.5.2

2 release files

2.5.1

2 release files

2.5.0

2 release files

2.4.7

2 release files

2.4.6

2 release files

2.4.5

2 release files

2.4.4

2 release files

2.4.3

2 release files

2.4.2

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.10

2 release files

2.3.9

2 release files

2.3.8

2 release files

2.3.7

2 release files

2.3.6

2 release files

2.3.5

2 release files

2.3.4

2 release files

2.3.3

2 release files

2.3.2

2 release files

2.3.1

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.8

2 release files

2.1.7

2 release files

2.1.6

2 release files

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.5.10

2 release files

1.5.9

2 release files

1.5.8

2 release files

1.5.7

2 release files

1.5.6

2 release files

1.5.5

2 release files

1.5.4

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.9

2 release files

1.4.8

2 release files

1.4.7

2 release files

1.4.6

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page