Help this project by Donation
- Update README.md and CHANGELOG.md.
- Updated the Argparse module to be usable with python 3.12.3.
- Added some exception classes to raise in the "argumentified" functions to show
parser error to the user:
ArgumentError
,IncompatibleArguments
,RequiredArgument
,TooFewArguments
- Added
Sequence[T]
as a supported type to the ColorizingArgumentParser. - Bug fixes.
- Update
README.md
.
- Added
<<
and>>
(left shift and right shift operators) tolog21.Logger.Logger
.
- Fixed Carriage Return Handling.
- Fixed setting level using
log21.basic_config
- Added more configuration for developer tools to the
pyproject.toml
file. - Added pre-commit.
- Fixed setting level using
log21.basic_config
- Fixed Carriage Return Handling.
- Update python version
- Renamed
crash_report.log
to.crash_report.log
. - Added "force" error handling method to
Logger.add_level
. - Changed the adding level error handling method to "ignore".
- Ability to add new methods to the Logger object for each custom level.
- Renamed
crash_report.log
to.crash_report.log
.
- Changed the adding level error handling method to "ignore".
- Ability to add new methods to the Logger object for each custom level.
- Update python version
- Added "force" error handling method to
Logger.add_level
.
- Improved compatibility
- Modified
automatic-release.yml
andpypi.yml
workflows to check the version - Added the support for more
type
s to pass toColorizingArgumentParser().add_argument(...)
:typing.Union
,typing.Optional
,typing.Literal
,enum.Enum
,tuple
andtyping.Required
. - Modified the way
Enum
s are handled in the Argument Parser. - Handled some
typing._SpecialForm
s. - A normal ArgumentGroup can now be required! (Unlike MutuallyExclusiveGroup it can have more than 1 option used at the same time)
argumentify
now supports async functions as the entry point.
Change in README.md.
- Added
encoding
tolog21.CrashReporter.FileReporter
. - Added configs for
pylint
,yapf
andisort
topyproject.toml
. - Added optional
dev
dependencies topyproject.toml
. - Improved overall code quality.
Added the Argumentify
module. Check the examples.
Fixed a bug in the TreePrint
class.
Added constant colors directly to the Colors module. Now you can do this:
from log21 import print
from log21.colors import GREEN, WHITE, RED
print(GREEN + 'This' + WHITE + ' is' + RED + ' Red')
Moved some dictionaries to __init__
methods.
colors
in Argparse.ColorizingHelpFormatter
class.
_level_name
in Formatters._Formatter
class and level_colors
in Formatters.ColorizingFormatter
class.
sign_colors
in PPrint.PrettyPrinter
class.
colors
in TreePrint.TreePrint.Node
class.
Improved type-hintings.
Switched from setup.py
build system to pyproject.toml
Added level_colors
argument to log21.get_logger
function with will be passed to the formatter and allows
user to set custom level colors while making a new logger.
Also changed most Dict
type hints to be Mapping
and list
to Sequence
to make the functions more general
and less strict.
Added extra_values
argument to CrashReporter.Formatter
which will let you pass extra static or dynamic values to the
report formatter.
They can be used in the format string. For dynamic values you can pass a function that takes no
arguments as the value.
Shortened the usage syntax for the CrashReporters:
import log21
# Define a ConsoleReporter object
console_reporter = log21.CrashReporter.ConsoleReporter()
# This works with other `log21.CrashReporter.Reporter` subclasses as well.
# Old syntax (still supported)
@console_reporter.reporter
def divide_old(a, b):
return a / b
# New Syntax
@console_reporter.reporter
def divide_new(a, b):
return a / b
console_crash_reporter
and file_crash_reporter
are removed!
Added no_color
parameter to ProgressBar.
Some bug fixes.
Improvements.
Bug Fixes.
Bug fixes and improvements.
- Made it more compatible with multi-threading.
- Fixed some bugs.
Minor fixes and improvements.
Minor fixes and improvements.
Added catch
and ignore
methods to log21.CrashReporter.Reporter
.
Added exceptions_to_catch
and exceptions_to_ignore
arguments to log21.CrashReporter.Reporter
class.
Added Print
logging level.
Minor improvements.
Added a new method to log21.Logger
class: log21.Logger.clear_line
. This method clears the current line in the
console and moves the cursor to the beginning of the line.
Fixed a bug that would cause an error creating a progress bar with no value set for width in systems without support for os.get_terminal_size().
Added additional_variables
argument to log21.ProgressBar
class. You can use it in order to add additional variables
to the progress bar:
import log21, time
progress_bar = log21.ProgressBar(format_='Iteration: {i} {prefix}{bar}{suffix} {percentage}%', style='{',
additional_variables={"i": 0})
for i in range(100):
progress_bar(i + 1, 100, i=i)
time.sleep(0.1)
# Iteration: 99 |██████████████████████████████████████████████████████████████████████████████| 100%
Added formatter
argument to StreamHandler
and FileHandler
. You can use it to set the formatter of the handler when
you create it. Added handlers
argument to Logger
. You can use it to add handlers to the logger when you create it.
Added progressbar custom formatting.
Now you can use your own formatting for the progressbar instead of the default one.
Let's see an example:
# We import the ProgressBar class from log21
from log21 import ProgressBar
# psutil is a module that can be used to get the current memory usage or cpu usage of your system
# If you want to try this example, you need to install psutil: pip install psutil
import psutil
# We use the time module to make a delay between the progressbar updates
import time
cpu_bar = ProgressBar(format_='CPU Usage: {prefix}{bar}{suffix} {percentage}%', style='{', new_line_when_complete=False)
while True:
cpu_bar.update(psutil.cpu_percent(), 100)
time.sleep(0.1)
Added CrashReporter!
You can use Reporter classes to monitor your program and send crash reports to the developer. It can help you fix the bugs and improve your program before your users get upset about it. See some examples in the log21/CrashReporter/Reporters.py file.
Bug fixes.
Added getpass
method to log21.Logger
class and added log21.getpass
function.
Bug fixes.
Added log21.input function.
Fixed import error in tkinter-less environments.
Minor changes.
Added optional shell support to the LoggingWindow.
Added LoggingWindow!
Added ProgressBar
class!
You can directly print a progress bar to the console using print_progress
method of log21.Logger
class.
OR
Use log21.ProgressBar
class witch is specifically designed for this purpose.
OR
Use log21.progress_bar
function (I don't recommend it!).
Minor changes.
Added log21.log
, log21.debug
, log21.info
, log21.warning
, log21.error
and some other functions.
Added log21.tree_print()
function.
Added log21.pprint()
function. It is similar to pprint.pprint()
function.
Added level_names
argument to Formatter classes.
level_names
can be used to change the name of logging level that appears while logging messages.
Minor changes.
log21.print
function added!
More description added.
ColorizingArgumentParser
improvements.
Setting custom formatting style and custom date-time formatting added to log21.get_logger
function.
Logger.write
edited. It's same as Logger.warning
but its default end
argument value is an empty string.
Logger.write
added. It's same as Logger.warning
Bug fixed:
>>> log21.get_logger()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\...\Python37-32\lib\site-packages\log21\__init__.py", line 44, in get_logger
raise TypeError('A logger name must be a string')
TypeError: A logger name must be a string
get_logger
improved.
Logger.print
added.
You can use Logger.print
to print a message using the current level of the logger class.
It gets printed with any level.
ColorizingArgumentParser
added.
You can use ColorizingArgumentParser
to have a colorful ArgumentParser.
StreamHandler
can handle new-line characters at the beginning of the message.
get_color
function now supports hexadecimal and decimal RGB values.