Skip to main content

Kakfa logging made simple with python, make your log messages as kafka events out-of-the-box!

Project description

Logging to kafka made simple with python.

1- Installation

  • pip install KakfaLogs

  • add .env file if not exist to the root directory of your project

2 -sample .env file

CRITICAL=1
WARNING=2
INFO=3
ERROR=4
METRIC=5
GENERATE_LOG_FILE=yes
DIR=/tmp/logs/
ENVIRONMENT=debug
APPLICATION=<your_app_name>
NOTIFY_URL=#
TEAM=de
APPLICATION_GROUP=tw
AGENT=kafka
KAFKA_BROKERS=localhost:9092
TOPIC=<your_topic>

3- configuration properties explained

TEAM
    de=data-engineering;ds=data science;se=software engineering

APPLICATION_GROUP
    tw=twitter
    nw=news;
    cv=covid-19
    ai=artificial intelligence

AGENT
    Allowed values : kafka
    kafka -->> logs will be sent to kafka to specified TOPIC and configured KAFKA_BROKERS

ENVIRONMENT=debug
    Allowed values : development, debug or production
DIR
    Log file path where logs will be generated.

GENERATE_LOG_FILE
    Allowed values : yes/no
    If GENERATE_LOG_FILE=yes, log messages being copied to file on location specified in DIR variable.
        eg:20210726.log

Note:

If Kafka brokers refused connection, the logs will be writing to file specified in DIR location with a file name prefix "failover_"

eg: failover_210803.log

4- Sample usage

import KafkaLogs as log

log.info("hello there!")
dict = {"count": 100, "date" : "2021-07-06"}
log.info(msg="Yet another log!", extra_data=dict)
log.error("Opps! that's an error.")
log.critical("Gosh! The application has encountered a fatal error!")
log.warning("That's a warning!")
dict = {"count": 100}
log.metrics(msg="",  extra_data=dict)

License:MIT

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

KafkaLogs-0.1.6.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file KafkaLogs-0.1.6.tar.gz.

File metadata

  • Download URL: KafkaLogs-0.1.6.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.6.9

File hashes

Hashes for KafkaLogs-0.1.6.tar.gz
Algorithm Hash digest
SHA256 1c45f89ac060f7cbfee0aae25b11b9bb971b04fe713f931320468282957291f4
MD5 f4c13690d1081cc500f0c9de04f54c1c
BLAKE2b-256 acd7f12f2b12a1c77bf9a47461699854f610319953721ef63c8c0549520306e3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page