This repository was archived by the owner on Jun 29, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +48
-3
lines changed Expand file tree Collapse file tree 4 files changed +48
-3
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,46 @@ Log Handler to ship logs to Kafka Producer. Compatible with Django.
99
1010| Version | Dependency |
1111| --------------| ------------------------|
12- | > ; = 1.x | kafka-python>=2.0.1 |
12+ | > ; = 1.x | kafka-python>=2.0.1 |
13+
14+
15+ #### Handlers
16+ - The package has a built in handler for Kafka: ` from python_logging_kafka import KafkaHandler `
17+ - KafkaHandler is a basic handler for sending logs to Kafka. Every record will be delivered using the exchange configured.
18+
19+
20+ #### Standalone Python
21+ ```
22+ class Main:
23+
24+ def __init__(self):
25+ logging.basicConfig(
26+ format='%(asctime)s %(levelname)s %(message)s',
27+ level=logging.INFO,
28+ datefmt='%m/%d/%Y %I:%M:%S %p'
29+ )
30+ self.logger = logging.getLogger('pylog')
31+
32+ ch = logging.StreamHandler()
33+ ch.setLevel(logging.INFO)
34+ formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
35+ ch.setFormatter(formatter)
36+ self.logger.addHandler(ch)
37+
38+ f1 = logging.FileHandler("pylog.log")
39+ self.logger.addHandler(f1)
40+
41+ kh = KafkaHandler('localhost:9092', "pylog")
42+ kh.setLevel(logging.INFO)
43+ self.logger.addHandler(kh)
44+
45+ def run(self):
46+ while True:
47+ log = input("> ")
48+ self.logger.info(log)
49+
50+
51+ if __name__ == '__main__':
52+ main = Main()
53+ main.run()
54+ ```
Original file line number Diff line number Diff line change 1+ from .handlers import KafkaHandler
2+
3+ __version__ = '1.0.0'
Original file line number Diff line number Diff line change 2222]
2323
2424setup (name = 'python-logging-kafka' ,
25- version = '1.0.0 ' ,
25+ version = '1.0.1 ' ,
2626 url = 'https://github.com/addu390/python-logging-kafka' ,
2727 description = 'Kafka log producer from Python/Django' ,
2828 long_description = README ,
Original file line number Diff line number Diff line change 11def mock_test ():
2- assert True == True
2+ assert True == True
You can’t perform that action at this time.
0 commit comments