Asynchronous log for python logging.
Project description
asynclog
asynclog
provide the asynchronous way for python logging. Leave the logging I/O(especially the network I/O when we want to logging to a network endpoint) to the asynchronous thread or asynchronous task provided by celery .
Requirements
- Python 3.5+
Install
python setup.py install
Usage
- Using thread
import logging
import time
from asynclog import AsyncLogDispatcher
def write_log(msg):
# Do write stuff, such as write log msg into network.
# ...
time.sleep(0.5)
logger = logging.getLogger()
logger.setLevel(logging.INFO)
handler = AsyncLogDispatcher(write_log)
handler.setLevel(logging.INFO)
logger.addHandler(handler)
logger.info('Test Log')
- Using Celery
from celery import shared_task
@shared_task
def write_task(msg):
# Write log in Network IO
print(msg)
celery_handler = AsyncLogDispatcher(write_task, use_thread=False, use_celery=True)
celery_handler.setLevel(logging.INFO)
logger.addHandler(celery_handler)
logger.info('Test Log')
Test
python -m unittest
....
----------------------------------------------------------------------
Ran 4 tests in 0.003s
OK
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
asynclog-0.1.4.tar.gz
(4.5 kB
view hashes)