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/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) diff --git a/backend/AnimatedDrawings/supervisord.conf b/backend/AnimatedDrawings/supervisord.conf index f4bdfd4a2..399d395f9 100644 --- a/backend/AnimatedDrawings/supervisord.conf +++ b/backend/AnimatedDrawings/supervisord.conf @@ -12,16 +12,24 @@ 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 +stderr_logfile_backups = 30 [program:application] 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 +stderr_logfile_backups = 30 environment=ENVIRONMENT=%(ENV_ENVIRONMENT)s,PYOPENGL_PLATFORM="osmesa" [program:celery] @@ -29,7 +37,11 @@ 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 +stderr_logfile_backups = 30 environment=ENVIRONMENT=%(ENV_ENVIRONMENT)s,PYOPENGL_PLATFORM="osmesa"