Skip to content

[FEATURE] Logging 추가하기#27

Merged
youyeon11 merged 5 commits intodevelopfrom
feat/add-logging-26
Oct 1, 2025
Merged

[FEATURE] Logging 추가하기#27
youyeon11 merged 5 commits intodevelopfrom
feat/add-logging-26

Conversation

@youyeon11
Copy link
Contributor

📌 작업 목적

기존에 간단히 print로만 콘솔에서 확인하던 것을
logging 라이브러리를 통하여 어플리케이션 관리 차원의 로깅으로 변경


🗂 작업 유형

  • 기능 추가 (Feature)
  • 버그 수정 (Bug Fix)
  • 리팩터링 (Refactor)
  • 성능 개선 (Performance)
  • 테스트 추가/수정 (Test)
  • 빌드/배포/환경 설정 (Chore)
  • 문서 수정 (Docs)

🔨 주요 작업 내용

  • logging_config.py
"formatters": {
    "default": {
        "format": "%(asctime)s %(levelname)s [%(name)s] %(message)s",
    },
},
  • FastAPI 앱 자체의 전체 로깅 포맷을 위와 같이 설정하였습니다. 위치에 대하여 출력이 추가로 됩니다
  • INFO 이상의 레벨들 전부 출력

  • 기존의 print를 전부 logging으로 변경하였습니다

🧪 테스트 결과

image

📎 관련 이슈


@gemini-code-assist
Copy link

Summary of Changes

Hello @youyeon11, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 Pull Request는 애플리케이션의 로깅 시스템을 print 문에서 Python의 logging 라이브러리로 전환하여 관리 효율성을 높이는 것을 목표로 합니다. 이를 통해 로그의 가독성을 향상시키고, 심각도별 관리를 가능하게 하며, 향후 로깅 시스템 확장을 위한 기반을 마련합니다. 전반적인 애플리케이션의 상태 모니터링 및 문제 진단 능력이 강화될 것입니다.

Highlights

  • 로깅 라이브러리 도입: 기존의 print 문을 대체하여 Python의 표준 logging 라이브러리를 애플리케이션 전반에 걸쳐 도입했습니다.
  • 중앙 집중식 로깅 설정: app/core/logging_config.py 파일을 새로 추가하여 애플리케이션의 로깅 포맷, 핸들러, 레벨 등을 중앙에서 설정할 수 있도록 했습니다.
  • 서비스 및 워커 로깅 강화: openai_service.py, predictor_service.py, tasks.py, worker.py 등 주요 서비스 및 워커 파일에 로깅을 적용하고, 초기화, 작업 진행, 오류 발생 시 상세한 로그를 기록하도록 개선했습니다.
  • 예외 처리 및 디버깅 개선: predictor_service.py 파일에 모델 및 JSON 로딩 과정에서의 FileNotFoundError, JSONDecodeError 등 다양한 예외 처리를 추가하고, 관련 오류 발생 시 logger.errorlogger.warning을 통해 상세한 정보를 기록하도록 하여 디버깅 용이성을 높였습니다.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

이번 PR은 기존의 print 구문을 logging 라이브러리로 대체하여 애플리케이션의 로깅 시스템을 개선하는 중요한 리팩터링 작업을 수행했습니다. 전반적으로 로깅 설정이 잘 구성되었고, predictor_service.py 등에서 오류 처리와 함께 상세한 로그가 추가되어 디버깅 및 유지보수성이 크게 향상되었습니다. 몇 가지 코드 일관성 및 의존성 관련 개선점을 제안드렸으니 확인 부탁드립니다.

state_dict = object[k]
break
try:
object = torch.load(model_path, map_location=self.device, weights_only=False)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

torch.load에서 weights_only=False를 사용하는 것은 신뢰할 수 없는 소스의 모델 파일을 로드할 때 임의 코드 실행으로 이어질 수 있는 보안 위험을 초래할 수 있습니다. 모델의 state_dict만 로드하는 것이 더 안전합니다. weights_only=True로 설정하고 state_dict를 로드하도록 코드를 수정하는 것을 강력히 권장합니다.

Suggested change
object = torch.load(model_path, map_location=self.device, weights_only=False)
object = torch.load(model_path, map_location=self.device, weights_only=True)

openai
timm No newline at end of file
timm
logging No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

logging 모듈은 Python 표준 라이브러리에 포함되어 있으므로 requirements.txt 파일에 명시할 필요가 없습니다. 이 줄을 삭제하여 불필요한 의존성을 제거하는 것이 좋습니다. PyPI에 있는 logging 패키지는 표준 라이브러리와 다른, 오래된 패키지일 수 있어 혼란을 야기하거나 빌드 문제를 일으킬 수 있습니다.

async def process_image_scan(job: ImageJob, redis_client: redis.Redis):
correlationId = job.correlationId
print(f"[task] Start image scan for job_id={correlationId}")
logging.info(f"[task] Start image scan for job_id={correlationId}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

로그 메시지에 [task] 접두사를 수동으로 추가하고 있습니다. 로깅 설정(logging_config.py)에서 포맷터가 %(name)s을 통해 로거 이름(예: app.worker.tasks)을 자동으로 포함하므로, 이 접두사는 중복 정보를 만듭니다. 가독성을 높이고 로그 메시지를 간결하게 유지하기 위해 이 파일의 다른 로그 메시지(34, 56, 59, 61행)에서도 [task] 접두사를 제거하는 것을 권장합니다.

Suggested change
logging.info(f"[task] Start image scan for job_id={correlationId}")
logging.info(f"Start image scan for job_id={correlationId}")


async def run(self):
print(f"[worker] start consumer={settings.CONSUMER_NAME} group={settings.GROUP_NAME} stream={settings.STREAM_JOB}")
logging.info(f"[worker] start consumer={settings.CONSUMER_NAME} group={settings.GROUP_NAME} stream={settings.STREAM_JOB}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

로그 메시지에 [worker] 접두사를 수동으로 추가하고 있습니다. 로깅 설정(logging_config.py)에서 포맷터가 %(name)s을 통해 로거 이름(예: app.worker.worker)을 자동으로 포함하므로, 이 접두사는 중복 정보를 만듭니다. 가독성을 높이고 로그 메시지를 간결하게 유지하기 위해 [worker] 접두사가 포함된 이 파일의 다른 로그 메시지(93, 138, 161, 164행)에서도 접두사를 제거하는 것을 권장합니다.

Suggested change
logging.info(f"[worker] start consumer={settings.CONSUMER_NAME} group={settings.GROUP_NAME} stream={settings.STREAM_JOB}")
logging.info(f"start consumer={settings.CONSUMER_NAME} group={settings.GROUP_NAME} stream={settings.STREAM_JOB}")

@youyeon11
Copy link
Contributor Author

Gemini 코드 리뷰 중 오류가 발생했습니다: 404 models/gemini-1.5-pro-latest is not found for API version v1beta, or is not supported for generateContent. Call ListModels to see the list of available models and their supported methods.

@gemini-code-assist
Copy link

안녕하세요 @youyeon11님, 오류 보고 감사합니다. "404 models/gemini-1.5-pro-latest is not found" 메시지는 Gemini 시스템 내부에서 모델을 찾거나 지원하는 데 문제가 발생했음을 나타냅니다. 이는 사용자 측에서 해결할 수 있는 문제가 아니며, 저희 시스템의 일시적인 문제일 수 있습니다. 이 문제를 보고해주셔서 감사합니다. 이 피드백은 서비스 개선에 큰 도움이 됩니다. 현재로서는 제가 직접 이 문제를 해결할 수는 없지만, 문제가 해결되면 다시 코드 리뷰를 지원해 드릴 수 있습니다.

@youyeon11 youyeon11 merged commit 9d767fe into develop Oct 1, 2025
@youyeon11 youyeon11 mentioned this pull request Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant