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 details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asynclog-0.1.4.tar.gz.
File metadata
- Download URL: asynclog-0.1.4.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b68df6f2205be12e94942ec4886c8ff776d5283450f24255aa639831ba579e8b
|
|
| MD5 |
b1fc44fe99d00dd36c7692ef3425b9b4
|
|
| BLAKE2b-256 |
e88a8153d9faae28a3c1b9bb4dbc181423997642c92779d061b42766b4003795
|
File details
Details for the file asynclog-0.1.4-py3-none-any.whl.
File metadata
- Download URL: asynclog-0.1.4-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4749dd541c452a7b7b023d205172b879cbb3f4098619d9f95720067cae08a9c6
|
|
| MD5 |
47772467a7420cd75ae99f22a8f01647
|
|
| BLAKE2b-256 |
d7ba011f069becd3c8852ebe4809d742e768bf171eb6e6fe22f704547f0b680a
|