Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit c65102c

Browse files
committed
Update readme
1 parent 26b78c4 commit c65102c

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
```

python_logging_kafka/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .handlers import KafkaHandler
2+
3+
__version__ = '1.0.0'

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
]
2323

2424
setup(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,

tests/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
def mock_test():
2-
assert True == True
2+
assert True == True

0 commit comments

Comments
 (0)