Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Create customer handlers to send logs to Kafka from Python/Django

NotificationsYou must be signed in to change notification settings

addu390/python-logging-kafka

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Log Handler to ship logs to Kafka Producer. Compatible with Django.

Installation

Versions

VersionDependency
>= 1.xkafka-python>=2.0.0

Handlers

  • 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.

Standalone Python

  • Referpython_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

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp