Skip to main content

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.

  1. git clone https://github.com/ELTE-DH/webarticlecurator.git
  2. Run make

On Windows or without Make (after cloning the repository):

  1. poetry install --no-root
  2. poetry build
  3. 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-0.0.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

mplogger-0.0.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file mplogger-0.0.1.tar.gz.

File metadata

  • Download URL: mplogger-0.0.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.8.10 Linux/5.4.0-96-generic

File hashes

Hashes for mplogger-0.0.1.tar.gz
Algorithm Hash digest
SHA256 342ffe8161af85dfcdecee8f3be86d8fab4ce7205b9c2f325b2360deb9d4d3c6
MD5 c6f97c4bc57ac9ef6d66dd9c6dcb2257
BLAKE2b-256 6541472f0ac71e3a35c6b88d1c96388f5bc50308cf65262e5dd98f721061dbf6

See more details on using hashes here.

File details

Details for the file mplogger-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: mplogger-0.0.1-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.10 Linux/5.4.0-96-generic

File hashes

Hashes for mplogger-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 79e61c138a08a2cd672e3576ba0e2ff7df758cb0d130ff0c08893b15ae422700
MD5 3d37cf42e190562a53d0bcd4430aa3f4
BLAKE2b-256 ff0766155c4c711146e9b825acde9d180c909558476feb1bf2986ab88d0303d1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page