Skip to content

Commit

Permalink
feat : logging to file
Browse files Browse the repository at this point in the history
  • Loading branch information
kunsonx committed Aug 13, 2024
1 parent 5c639fc commit 566a74c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions kafka_connector_starter/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import signal
import time
import logging
from logging.handlers import RotatingFileHandler

import httpx

Expand All @@ -26,11 +27,16 @@ def exit_gracefully(self, signum, frame):


def main():
logging.basicConfig(
datefmt="%Y-%m-%d %H:%M:%S",
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
# setup handler max bytes is 1GB and backup count is 5
handler = RotatingFileHandler(
"kafka_connector_starter.log", maxBytes=1 << 30, backupCount=5
)
logger = logging.getLogger(__name__)
handler.setFormatter(
logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
)
logger = logging.getLogger("kafka_connector_starter")
logger.setLevel(logging.INFO)
logger.addHandler(handler)

logger.info("Starting Kafka Connector Starter")

Expand Down

0 comments on commit 566a74c

Please sign in to comment.