This repository was archived by the owner on Jun 29, 2022. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork1
addu390/python-logging-kafka
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Log Handler to ship logs to Kafka Producer. Compatible with Django.
- Install using PIP:
pip install -i https://test.pypi.org/simple/ python-logging-kafka - (Work In Progress):https://test.pypi.org/project/python-logging-kafka/
| Version | Dependency |
|---|---|
| >= 1.x | kafka-python>=2.0.0 |
- The package has a built in handler for Kafka:
from python_logging_kafka import KafkaHandler - KafkaHandler is a basic handler for sending logs to Kafka. Every record will be delivered using the exchange configured.
- Refer
python_logging_kafka/example.py
class Main: def __init__(self): logging.basicConfig( format='%(asctime)s %(levelname)s %(message)s', level=logging.INFO, datefmt='%m/%d/%Y %I:%M:%S %p' ) self.logger = logging.getLogger('pylog') ch = logging.StreamHandler() ch.setLevel(logging.INFO) formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') ch.setFormatter(formatter) self.logger.addHandler(ch) f1 = logging.FileHandler("pylog.log") self.logger.addHandler(f1) kh = KafkaHandler('localhost:9092', "pylog") kh.setLevel(logging.INFO) self.logger.addHandler(kh) def run(self): while True: log = input("> ") self.logger.info(log)if __name__ == '__main__': main = Main() main.run()About
Create customer handlers to send logs to Kafka from Python/Django
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published