Skip to content

Commit

Permalink
Merge pull request #594 from tukcomCD2024/fix/file_logging-animation-…
Browse files Browse the repository at this point in the history
…B-#587

fix : file logging 방식 변경
  • Loading branch information
seokho-1116 authored Jul 30, 2024
2 parents 455efb2 + ef86da7 commit d05e378
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions backend/AnimatedDrawings/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ RUN pip install -e .

WORKDIR /app/application

RUN mkdir log

CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
17 changes: 6 additions & 11 deletions backend/AnimatedDrawings/application/logging/logger_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,29 @@ 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: 설정할 로거
:param output_file_path: 로그를 기록할 파일의 경로
"""
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)
3 changes: 1 addition & 2 deletions backend/AnimatedDrawings/application/task/base_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
24 changes: 18 additions & 6 deletions backend/AnimatedDrawings/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,36 @@ 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]
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"

0 comments on commit d05e378

Please sign in to comment.