From f208b3b7d3ea5f81b201d5b7923f2b98a851e2ce Mon Sep 17 00:00:00 2001 From: hong seokho Date: Tue, 30 Jul 2024 10:29:45 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix=20:=20file=20handler=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/logging/logger_factory.py | 17 ++++++----------- .../application/task/base_task.py | 3 +-- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/backend/AnimatedDrawings/application/logging/logger_factory.py b/backend/AnimatedDrawings/application/logging/logger_factory.py index b0f1f4f3c..4de066433 100644 --- a/backend/AnimatedDrawings/application/logging/logger_factory.py +++ b/backend/AnimatedDrawings/application/logging/logger_factory.py @@ -18,13 +18,13 @@ def get_logger(name: str) -> logging.Logger: LoggerFactory._setup_handler(LoggerConfig.FORMAT_STRING, LoggerConfig.LOGGING_LEVEL, - logger, - LoggerConfig.APPLICATION_OUTPUT_FILE_PATH) + logger + ) return logger @staticmethod - def setup_logger(logger: logging.Logger, output_file_path: str) -> None: + def setup_logger(logger: logging.Logger) -> None: """ 파라미터로 받은 로거에 포맷터를 설정한다. :param logger: 설정할 로거 @@ -32,20 +32,15 @@ def setup_logger(logger: logging.Logger, output_file_path: str) -> None: """ LoggerFactory._setup_handler(LoggerConfig.FORMAT_STRING, LoggerConfig.LOGGING_LEVEL, - logger, - output_file_path) + logger + ) @staticmethod - def _setup_handler(format_string, level, logger, output_file_path): + def _setup_handler(format_string, level, logger): formatter = logging.Formatter(format_string) stream_handler = logging.StreamHandler(sys.stdout) stream_handler.setLevel(level) stream_handler.setFormatter(formatter) - file_handler = logging.FileHandler(filename=output_file_path) - file_handler.setLevel(level) - file_handler.setFormatter(formatter) - - logger.addHandler(file_handler) logger.addHandler(stream_handler) diff --git a/backend/AnimatedDrawings/application/task/base_task.py b/backend/AnimatedDrawings/application/task/base_task.py index 22595acfe..ab9f5487c 100644 --- a/backend/AnimatedDrawings/application/task/base_task.py +++ b/backend/AnimatedDrawings/application/task/base_task.py @@ -5,7 +5,6 @@ from celery.utils.log import get_task_logger from kombu import Queue, Exchange -from application.config.logger_config import LoggerConfig from application.config.queue_config import QueueConfig from application.kombu_connection_pool import producers, connection from application.logging.logger_factory import LoggerFactory @@ -24,7 +23,7 @@ def __init__(self): @celery.signals.after_setup_task_logger.connect def on_after_setup_logger(logger, **kwargs): - LoggerFactory.setup_logger(logger, LoggerConfig.CELERY_OUTPUT_FILE_PATH) + LoggerFactory.setup_logger(logger) def before_start(self, task_id, args, kwargs): self.task_logger.debug(kwargs) From 70c342b8a7ad10274439bd48b90ac51dc7b1a695 Mon Sep 17 00:00:00 2001 From: hong seokho Date: Tue, 30 Jul 2024 10:29:55 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat=20:=20log=20backup=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/AnimatedDrawings/supervisord.conf | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backend/AnimatedDrawings/supervisord.conf b/backend/AnimatedDrawings/supervisord.conf index f4bdfd4a2..613930b30 100644 --- a/backend/AnimatedDrawings/supervisord.conf +++ b/backend/AnimatedDrawings/supervisord.conf @@ -14,6 +14,10 @@ priority = 100 loglevel=info stdout_logfile = /var/log/flower.log stderr_logfile = /var/log/flower.err +stdout_logfile_maxbytes = 50MB +stdout_logfile_backups = 30 +stderr_logfile_maxbytes = 50MB +stderr_logfile_backups = 30 [program:application] directory = /app/application @@ -22,6 +26,10 @@ loglevel=info priority = 100 stdout_logfile = /var/log/application.log stderr_logfile = /var/log/application.err +stdout_logfile_maxbytes = 50MB +stdout_logfile_backups = 30 +stderr_logfile_maxbytes = 50MB +stderr_logfile_backups = 30 environment=ENVIRONMENT=%(ENV_ENVIRONMENT)s,PYOPENGL_PLATFORM="osmesa" [program:celery] @@ -31,5 +39,9 @@ priority = 200 loglevel=info stdout_logfile = /var/log/celeryd.log stderr_logfile = /var/log/celeryd.err +stdout_logfile_maxbytes = 50MB +stdout_logfile_backups = 30 +stderr_logfile_maxbytes = 50MB +stderr_logfile_backups = 30 environment=ENVIRONMENT=%(ENV_ENVIRONMENT)s,PYOPENGL_PLATFORM="osmesa" From ef86da726402f38ac9f3e405240abb5c50c649bb Mon Sep 17 00:00:00 2001 From: hong seokho Date: Tue, 30 Jul 2024 10:45:16 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix=20:=20log=20=ED=8C=8C=EC=9D=BC=EB=A1=9C?= =?UTF-8?q?=20=EC=88=98=EC=A7=91=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../animation-application-prod-ci-cd-flow.yml | 2 +- backend/AnimatedDrawings/Dockerfile | 2 ++ backend/AnimatedDrawings/supervisord.conf | 12 ++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/animation-application-prod-ci-cd-flow.yml b/.github/workflows/animation-application-prod-ci-cd-flow.yml index 4f21b7266..7c967e97a 100644 --- a/.github/workflows/animation-application-prod-ci-cd-flow.yml +++ b/.github/workflows/animation-application-prod-ci-cd-flow.yml @@ -86,7 +86,7 @@ jobs: aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username ${{ secrets.AWS_DOCKER_USER }} --password-stdin ${{ secrets.AWS_USER_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com docker image prune -f docker pull ${{ steps.meta.outputs.tags }} - docker run -d -p 5555:5555 -p 9001:9001 --name animated_drawings -e ENVIRONMENT='dev' ${{ steps.meta.outputs.tags }} + docker run -d -p 5555:5555 -p 9001:9001 --name animated_drawings -v log_volume:/app/application/log -e ENVIRONMENT='dev' ${{ steps.meta.outputs.tags }} - name: Remove Github Actions IP from security group if: always() diff --git a/backend/AnimatedDrawings/Dockerfile b/backend/AnimatedDrawings/Dockerfile index 10a575a4a..61cd8c0a1 100644 --- a/backend/AnimatedDrawings/Dockerfile +++ b/backend/AnimatedDrawings/Dockerfile @@ -25,4 +25,6 @@ RUN pip install -e . WORKDIR /app/application +RUN mkdir log + CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"] diff --git a/backend/AnimatedDrawings/supervisord.conf b/backend/AnimatedDrawings/supervisord.conf index 613930b30..399d395f9 100644 --- a/backend/AnimatedDrawings/supervisord.conf +++ b/backend/AnimatedDrawings/supervisord.conf @@ -12,8 +12,8 @@ directory = /app/application command = /opt/conda/envs/animated_drawings/bin/celery -A celery_app flower --conf="/app/application/config/flowerconfig.py" priority = 100 loglevel=info -stdout_logfile = /var/log/flower.log -stderr_logfile = /var/log/flower.err +stdout_logfile = /app/application/log/flower.log +stderr_logfile = /app/application/log/flower.err stdout_logfile_maxbytes = 50MB stdout_logfile_backups = 30 stderr_logfile_maxbytes = 50MB @@ -24,8 +24,8 @@ directory = /app/application command = /opt/conda/envs/animated_drawings/bin/python3 -u animation_queue.py loglevel=info priority = 100 -stdout_logfile = /var/log/application.log -stderr_logfile = /var/log/application.err +stdout_logfile = /app/application/log/application.log +stderr_logfile = /app/application/log/application.err stdout_logfile_maxbytes = 50MB stdout_logfile_backups = 30 stderr_logfile_maxbytes = 50MB @@ -37,8 +37,8 @@ directory = /app/application command = /opt/conda/envs/animated_drawings/bin/celery -A celery_app worker priority = 200 loglevel=info -stdout_logfile = /var/log/celeryd.log -stderr_logfile = /var/log/celeryd.err +stdout_logfile = /app/application/log/celeryd.log +stderr_logfile = /app/application/log/celeryd.err stdout_logfile_maxbytes = 50MB stdout_logfile_backups = 30 stderr_logfile_maxbytes = 50MB