From 22f1b84fa6fa30f2c97308cf521f2e451e16e81b Mon Sep 17 00:00:00 2001 From: CodeWriter21 Date: Fri, 14 Apr 2023 23:02:59 +0430 Subject: [PATCH] Some bug fixes. --- CHANGES-LOG.md | 4 ++++ README.md | 6 +++--- log21/Formatters.py | 15 ++++++++++++++- log21/__init__.py | 4 ++-- setup.py | 2 +- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CHANGES-LOG.md b/CHANGES-LOG.md index 6528cc9..887aac0 100644 --- a/CHANGES-LOG.md +++ b/CHANGES-LOG.md @@ -6,6 +6,10 @@ Help this project by [Donation](DONATE.md) Changes log ----------- +### 2.4.4 + +Some bug fixes. + ### 2.4.3 Improvements. diff --git a/README.md b/README.md index c02243f..ae34571 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ 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 ++ 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. @@ -53,9 +53,9 @@ python setup.py install Changes ------- -### 2.4.3 +### 2.4.4 -Improvements. +Some bug fixes. [Full Changes Log](https://github.com/MPCodeWriter21/log21/blob/master/CHANGES-LOG.md) diff --git a/log21/Formatters.py b/log21/Formatters.py index a08682b..8df2aab 100644 --- a/log21/Formatters.py +++ b/log21/Formatters.py @@ -11,7 +11,7 @@ class _Formatter(__Formatter): - level_names: _Dict[int, str] = { + _level_names: _Dict[int, str] = { DEBUG: 'DEBUG', INFO: 'INFO', WARNING: 'WARNING', @@ -52,6 +52,19 @@ def __init__(self, fmt: str = None, datefmt: str = None, style: str = '%', level for level, name in level_names.items(): self.level_names[level] = name + @property + def level_names(self): + return self._level_names + + @level_names.setter + def level_names(self, level_names): + if level_names: + if not isinstance(level_names, _Dict): + raise TypeError('`level_names` must be a dictionary!') + self._level_names = level_names + else: + self._level_names = dict() + def format(self, record) -> str: record.message = record.getMessage() if self.usesTime(): diff --git a/log21/__init__.py b/log21/__init__.py index 0884b19..67861bd 100644 --- a/log21/__init__.py +++ b/log21/__init__.py @@ -22,7 +22,7 @@ from log21.Formatters import ColorizingFormatter, DecolorizingFormatter from log21.Colors import Colors, get_color, get_colors, ansi_escape, get_color_name, closest_color -__version__ = "2.4.3" +__version__ = "2.4.4" __author__ = "CodeWriter21 (Mehrad Pooryoussof)" __github__ = "Https://GitHub.com/MPCodeWriter21/log21" __all__ = ['ColorizingStreamHandler', 'DecolorizingFileHandler', 'ColorizingFormatter', 'DecolorizingFormatter', @@ -53,7 +53,7 @@ def _prepare_formatter(fmt: str = None, style: str = '%', datefmt: str = "%H:%M: fmt = '\r' + fmt # Defines the formatter formatter = formatter_class(fmt, datefmt, style=style) - if isinstance(formatter, Formatters._Formatter): + if isinstance(formatter, Formatters._Formatter) and level_names: formatter.level_names = level_names if not colorize_time_and_level and isinstance(formatter, ColorizingFormatter): for key in formatter.level_colors: diff --git a/setup.py b/setup.py index cd98e76..136d0ae 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ long_description = file.read() DESCRIPTION = 'A simple logging package that helps you log colorized messages in Windows console.' -VERSION = '2.4.3' +VERSION = '2.4.4' setup( name='log21',