MPLogger
Multi-processing capable print-like logger for Python
Requirements and Installation
Python 3.8+ is required
Pip
pip install mplogger
Manual
Poetry and (optionally) GNU Make are required.
git clone https://github.com/ELTE-DH/MPLogger.git- Run
make
On Windows or without Make (after cloning the repository):
poetry install --no-rootpoetry buildpoetry run pip install --upgrade dist/*.whl(the correct filename must be specified on Windows)
Usage
Single-process
from mplogger import Logger
# Initialize logger (default: STDERR only with INFO level)
logger = Logger(log_filename, logfile_mode, logfile_encoding, logfile_level, console_stream, console_level, console_format, file_format)
logger.log('INFO', 'First argument log level as string')
logger.log('WARNING', 'THIS IS A WARNING!', 'In multiple lines', 'just like print()', sep='\n')
logger.log('CRITICAL', 'Can also set line endings!', end='\r\n')
Dummy-logger
from mplogger import DummyLogger
# Initialize logger (accepts any params)
logger = DummyLogger()
# Log function has the same API, but nothing happens
logger.log('INFO', 'First argument log level as string')
logger.log('WARNING', 'THIS IS A WARNING!', 'In multiple lines', 'just like print()', sep='\n')
logger.log('CRITICAL', 'Can also set line endings!', end='\r\n')
Multi-process
from itertools import repeat
from multiprocessing import Pool, Manager, current_process
from mplogger import Logger
def worker_process(par):
state, lq = par
retl = []
for n in range(100):
lq.log('WARNING', f'{current_process().name} message{state} {n}')
lq.log('WARNING', f'{current_process().name} finished')
return retl
log_obj = Logger('test.log', 'w') # Apply all parameters for logger here!
log_obj.log('INFO', 'NORMAL LOG BEGIN') # Normal logging
with Manager() as man:
log_queue = man.Queue()
with log_obj.init_mp_logging_context(log_queue) as mplogger, Pool() as p:
# Here one can log parallel from all processes!
return_queue = p.imap(worker_process, zip(range(10), repeat(mplogger)), chunksize=3)
for _ in return_queue:
pass
log_obj.log('INFO', 'NORMAL LOG END') # Normal logging
Licence
This project is licensed under the terms of the GNU LGPL 3.0 license.
Metadata
Release files for mplogger 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 | |
|---|---|---|---|---|
| mplogger-1.1.0.tar.gz | 7.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mplogger-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.0 kB
Release files / mplogger-1.1.0.tar.gz
| Download URL | mplogger-1.1.0.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b0a7454c0cca7d6b6463ce84ff56400c2187313a6d885499b5809dd4a49ed35
|
|
BLAKE2b-256 checksum How to use checksums |
503ed0efaf3bfb267c00cf3a7c05774d8cd017801d02aaed5e45afd03e79e1fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.6 Linux/5.15.0-57-generic
|
Release files / mplogger-1.1.0-py3-none-any.whl
| Download URL | mplogger-1.1.0-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
58060c81e20edf1f6f5483bb0d8d9f867728f90ac5590b956e2532919417cc23
|
|
BLAKE2b-256 checksum How to use checksums |
0655312d5c239afbfe1e1af61a5ac0b94899dac0c9b0018fe97273b60f5b75e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.6 Linux/5.15.0-57-generic
|
Security for mplogger 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.