From 80e20f0c552be5ba0807d59e1e6b81044d46ff1e Mon Sep 17 00:00:00 2001 From: fernandoataoldotcom Date: Thu, 26 Oct 2023 04:47:39 +0000 Subject: [PATCH] refactor: use glueops helpers --- Dockerfile | 2 ++ main.py | 25 +++++-------------------- requirements.txt | 3 ++- src/json_log_formatter.py | 17 ----------------- 4 files changed, 9 insertions(+), 38 deletions(-) delete mode 100644 src/json_log_formatter.py diff --git a/Dockerfile b/Dockerfile index 3a86c59..0c2a9bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.11.6-alpine3.18 +RUN pip install --upgrade pip + COPY requirements.txt /app/requirements.txt WORKDIR /app RUN pip install -r requirements.txt diff --git a/main.py b/main.py index 2452a2a..a1abe3c 100644 --- a/main.py +++ b/main.py @@ -1,32 +1,17 @@ -import logging import os import time import requests +from glueops.setup_logging import configure as go_configure_logging from kubernetes import client, config from src.get_github_api_token import get_github_api_token -from src.json_log_formatter import JsonFormatter #=== configure logging -# json formatter -json_formatter = JsonFormatter() - -# stream handler -stream_handler = logging.StreamHandler() -stream_handler.setFormatter(json_formatter) -stream_handler.setLevel(os.getenv( - 'PYTHON_LOG_LEVEL', - 'INFO' -)) - -# configure logger -logger = logging.getLogger('PULL_REQUEST_BOT') -logger.setLevel(os.getenv( - 'PYTHON_LOG_LEVEL', - 'INFO' -)) -logger.addHandler(stream_handler) +logger = go_configure_logging( + name='PULL_REQUEST_BOT', + level=os.getenv('PYTHON_LOG_LEVEL', 'INFO') +) # setting cluster config try: diff --git a/requirements.txt b/requirements.txt index b20b1d7..7dfb05f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ jwt==1.3.1 kubernetes==27.2.0 -requests==2.31.0 \ No newline at end of file +requests==2.31.0 +glueops-helpers @ https://github.com/GlueOps/python-glueops-helpers-library/archive/refs/tags/v0.2.0.zip \ No newline at end of file diff --git a/src/json_log_formatter.py b/src/json_log_formatter.py deleted file mode 100644 index 060f67b..0000000 --- a/src/json_log_formatter.py +++ /dev/null @@ -1,17 +0,0 @@ -import json -import logging - - -class JsonFormatter(logging.Formatter): - def format(self, record): - log_entry = { - 'timestamp': self.formatTime(record, self.datefmt), - 'name': record.name, - 'level': record.levelname, - 'message': record.getMessage(), - } - - if record.exc_info: - log_entry['exception'] = self.formatException(record.exc_info) - - return json.dumps(log_entry)