Multi-processing capable print-like logger for Python
Project description
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/webarticlecurator.git
- Run
make
On Windows or without Make (after cloning the repository):
poetry install --no-root
poetry build
poetry run pip install --upgrade dist/*.whl
(the correct filename must be specified on Windows)
Usage
Single-process
from MLPlogger 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')
Multi-process
from itertools import repeat
from multiprocessing import Pool, Manager, current_process
from MLPlogger 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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mplogger-1.0.0.tar.gz
(6.9 kB
view details)
Built Distribution
File details
Details for the file mplogger-1.0.0.tar.gz
.
File metadata
- Download URL: mplogger-1.0.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.8.3 Linux/5.11.0-1028-gcp
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 928b92ea5984742fc94f4419236ee48bc8d68d330a875ca8be8307f352d92007 |
|
MD5 | 1c70c3d53124a184cb074429dac11981 |
|
BLAKE2b-256 | fa54583301cb0f6eacdfe533d426a7bb0c402b84aa49cf1d83dd27a78872cc37 |
File details
Details for the file mplogger-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: mplogger-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.8.3 Linux/5.11.0-1028-gcp
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 192e02cdd48cdcb6a72e7af2dec69f47c0c77dcc8487488ba8b5cbbbc13aa23d |
|
MD5 | e0436d166f8e11d22f8126df0aab3d4f |
|
BLAKE2b-256 | 254877babcea1b353c63b52a574f0ae17f24e2a07431ec292ce86a460dfeaddd |