Loggerric
A logging utility for CLI applications. Offers colorful CLI outputs via ANSI escape characters, aswell as filelogging and a bunch of quality of life features.
Features
- Logging: Structured logging with levels
INFOWARNERRORDEBUGand highlighting. - Filelogging: Automatic logging to file with ISO timestamps and filepath descriptors.
- Pretty Printing: Pretty print different data types with indentation support.
- Tables: Print data tables in different styles, handles autosizing of the headers.
- Progress Bars: Real-time progressbars with metric labels like ETA, elapsed, etc.
- Prompts: Interactive user input with optional choices and default values.
- Timers: Measure execution time of code snippets with ease.
- Timestamps: Optional, can be used independently, supports rolling differences.
- Log Manager: Optional, can be used to disable logging from certain files.
Installation
pip install loggerric2
Dependencies:
pip install colorama
get_version method
import loggerric2 as lr2
lr2.get_version() # Uses the Major.Minor.Patch format.
Log class
import loggerric2 as lr2
# All logging supports automatic deduplication
lr2.Log.info('Output an information message!')
lr2.Log.warn('You can also do warning messages!', highlight='warning')
lr2.Log.error('Here is an error message!', hl='error')
lr2.Log.debug('You can highlight multiple segments!', hl=['highlight', 'segments'])
# Error logging accepts exception objects and an exit code for automatic exiting of the program
lr2.Log.error(Exception('Oh no!'))
lr2.Log.error('Custom message', e=Exception('Then the exception'))
lr2.Log.error('Critical error!', exit_code=1) # Since `exit_code` is not None, it will quit
lr2.Log.disable_level('debug') # Now all debug logs wont be logged to CLI or file.
lr2.Log.enable_level('debug') # Re-enable the debug logging level again.
lr2.Log.set_log_filepath(path='./logs') # Make sure to set the filepath before enabling.
lr2.Log.set_filelogging_state('enabled') # Enable filelogging.
ProgressBar class
import loggerric2 as lr2
# This will print a progress bar to the CLI.
for i in lr2.ProgressBar(range(100)):
...
# Can also create an instance instead of wrapping an iterator.
prog = ProgressBar(end_index=10)
for i in range(1, 11):
...
prog.update(i) # Need to manually call update.
Table class
import loggerric2 as lr2
headers = ('Item Name', 'Quantity', 'Price')
rows = (
('Socks', 24, '$2.24'),
('Trex', 1, '$12.2M'),
('Apple', 912, '$0.54')
)
lr2.Table.minimalistic(headers, rows)
lr2.Table.boxed(headers, rows)
lr2.Table.borderless(headers, rows)
# Also supports building a table from a list of dictionaries
products = [
{ 'Item': 'Socks', 'Stock': 24, 'Price': '$2.24' },
{ 'Item': 'Trex', 'Stock': 1, 'Price': '$12.2M', 'Is Rare': True }, # Extra cols does not break
{ 'Item': 'Apple', 'Stock': 912, 'Price': '$0.54' }
]
Table.minimalistic(lod=products)
Table.boxed(lod=products)
Table.borderless(lod=products)
Timer class
import loggerric2 as lr2
with Timer(name='Timer Name') as timer:
...
duration = timer.get_duration_ms()
duration_f = timer.get_formatted_duration()
pretty_print method
import loggerric2 as lr2
lr2.pretty_print([1, 2, 'three', 4.5])
lr2.pp({ 'Key': 'Value', 'Downloads': 123 }) # Exact same as pretty_print, just an alias
prompt method
import loggerric2 as lr2
# Prompt without options, just a regular prompt
option = prompt('Question')
# Prompt with options, still accepts other options than specified
option = prompt('Question', options=['Option 1', 'Option 2'])
# Prompt with options, and a default option if user just clicks enter
option = prompt('Question', option=['One', 'Two'], default_option='One')
# Also supports case sensitive options
option = prompt('Question', option=['One', 'Two'], case_sensitive=True)
# And an autocomplete for long options or faster prompting
option = prompt('Question', option=['One', 'Two'], auto_complete_option=True)
Timestamp class
import loggerric2 as lr2
lr2.Timestamp.set_timezone(datetime.timezone.utc) # Sets the timezone to use for timestamps.
# Set the format that will be used when getting timestamps
lr2.Timestamp.set_format('{DD}/{MO}/{YY} {HH}:{MI}:{SS}.{MS} T+{DH}:{DM}:{DS}.{DM}')
lr2.Timestamp.get() # Gets the current timestamp with the set format and timezone
lr2.Timestamp.get_iso() # Gets the current ISO timestamp.
lr2.Timestamp.set_state('disabled') # Disable the timestamps on the logs
lr2.Timestamp.set_state('enabled') # Re-enable them again
LogManager class
import loggerric2 as lr2
# Get the file of the function that called this method
caller = lr2.LogManager.get_method_caller()
# Get the file that created a class instance
owner = lr2.LogManager.get_class_instance_owner_file()
# Set how many directories of the caller path to show
lr2.LogManager.set_caller_file_depth(2)
# Get the formatted caller filepath
lr2.LogManager.get_caller_file()
# Get the filepath without ANSI formatting
lr2.LogManager.get_caller_file(no_ansi=True)
# Skip additional caller frames
lr2.LogManager.get_caller_file(skip_extra=1)
# Blacklist the current file
lr2.LogManager.blacklist_this_file()
# Remove the current file from the blacklist
lr2.LogManager.remove_this_files_blacklist()
# Check if the current file is blacklisted
lr2.LogManager.is_caller_blacklisted()
# Add a file or path to the blacklist
lr2.LogManager.add_blacklist('debug.py')
# Remove a file or path from the blacklist
lr2.LogManager.blacklist_remove('debug.py')
# Get all blacklisted paths
lr2.LogManager.get_blacklist()
# Check if a specific path is blacklisted
lr2.LogManager.is_blacklisted('debug.py')
Metadata
Release files for loggerric2 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| loggerric2-1.1.0.tar.gz | 19.2 kB | Without provenance | Details for loggerric2-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| loggerric2-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for loggerric2-1.1.0-py3-none-any.whl |
Total release size: 39.4 kB
Release files / loggerric2-1.1.0.tar.gz
| Download URL | loggerric2-1.1.0.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
552f156c74dd97c3bc6413974dfe09476f2115d5c4322b5227fe350bc90b733b
|
|
BLAKE2b-256 checksum How to use checksums |
d188b438503f1b1512a93282dc0fb7e5be07f477959b151685b9014359bf7987
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Release files / loggerric2-1.1.0-py3-none-any.whl
| Download URL | loggerric2-1.1.0-py3-none-any.whl |
|---|---|
| Size | 20.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0b477fd9b00d7cccd2871de494f293656e89e72845fa723106c4f7c420480a0f
|
|
BLAKE2b-256 checksum How to use checksums |
83462c738f3eb5df2785ace1af748c6900c6837cbded361f2bbc3fe66d648ea2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.5
|
Security for loggerric2 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.