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

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.4.0.tar.gz (83.5 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.4.0-py3-none-any.whl (91.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: log21-3.4.0.tar.gz
  • Upload date:
  • Size: 83.5 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for log21-3.4.0.tar.gz
Algorithm Hash digest
SHA256 e058e535712ba9263ed95b63cbf6a3537c940156da96f8232dda8a34b96e57ed
MD5 98a4eb1ccab8863f6a426b6919c0e5af
BLAKE2b-256 4e729ee35ca54430f23b061705309b0e1e8574dbecf6d16f7e04ce14045e78c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: log21-3.4.0-py3-none-any.whl
  • Upload date:
  • Size: 91.5 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for log21-3.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8c848481fd4ca8664e3aa7fa545df2c7faf61e339e6b385ebc76c5f02871931d
MD5 365439f709727751c3da3d2f9036b272
BLAKE2b-256 b1a212676f09248d73ac1b98ccb6d15114831eba936f78c4fdafc5a49a34ca68

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

3.4.0 This release

2 files

3.3.3

2 files

3.3.2

2 files

3.3.1

2 files

3.3.0

2 files

3.2.0

2 files

3.1.0

2 files

3.0.2

2 files

3.0.1

2 files

3.0.0

2 files

2.10.2

2 files

2.10.1

2 files

2.10.0

2 files

2.9.2

2 files

2.9.1

2 files

2.9.0

2 files

2.8.1

2 files

2.8.0

2 files

2.7.1

2 files

2.7.0

2 files

2.6.2

2 files

2.6.1

2 files

2.6.0

2 files

2.5.4

2 files

2.5.3

2 files

2.5.2

2 files

2.5.1

2 files

2.5.0

2 files

2.4.7

2 files

2.4.6

2 files

2.4.5

2 files

2.4.4

2 files

2.4.3

2 files

2.4.2

2 files

2.4.1

2 files

2.4.0

2 files

2.3.10

2 files

2.3.9

2 files

2.3.8

2 files

2.3.7

2 files

2.3.6

2 files

2.3.5

2 files

2.3.4

2 files

2.3.3

2 files

2.3.2

2 files

2.3.1

2 files

2.3.0

2 files

2.2.0

2 files

2.1.8

2 files

2.1.7

2 files

2.1.6

2 files

2.1.5

2 files

2.1.4

2 files

2.1.3

2 files

2.1.2

2 files

2.1.1

2 files

2.1.0

2 files

2.0.0

2 files

1.5.10

2 files

1.5.9

2 files

1.5.8

2 files

1.5.7

2 files

1.5.6

2 files

1.5.5

2 files

1.5.4

2 files

1.5.3

2 files

1.5.2

2 files

1.5.1

2 files

1.5.0

2 files

1.4.12

2 files

1.4.11

2 files

1.4.10

2 files

1.4.9

2 files

1.4.8

2 files

1.4.7

2 files

1.4.6

2 files

1.4.5

2 files

1.4.4

2 files

1.4.3

2 files

1.4.2

2 files

1.4.1

2 files

1.3.2

2 files

1.3.1

2 files

1.3.0

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.0

2 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