Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Config] 서버 로깅 설정 및 오류 포멧 설정 #44

Merged
merged 2 commits into from
Nov 10, 2024

Conversation

jjeonghak
Copy link
Collaborator

관련 이슈 번호

#2

작업 내용

  • http 요청 및 응답 로깅 설정
  • 오류 응답 포멧 설정

고민과 학습내용

서버에서 http 요청이 올때 간단하게 로그를 남기고 응답을 할때나 오류가 발생했을때도 로그를 남기도록 설정했습니다.

@jjeonghak jjeonghak added Config 환경 설정, 기타 작업 BE 서버 작업 labels Nov 10, 2024
@jjeonghak jjeonghak self-assigned this Nov 10, 2024
const { statusCode } = context.switchToHttp().getResponse();
const delay = Date.now() - now;
this.logger.log(
`[RESPONSE] ${method} ${url} ${ip} - ${statusCode} \x1b[33m+${delay}ms\x1b[0m`
Copy link
Collaborator

Choose a reason for hiding this comment

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

🟢
템플릿 리터럴이 길어지면 무슨 역할을 하는지 알아보기가 힘들어진다는 피드백을 받았던 적이 있습니다!
아직 짧아서 괜찮지만, createResponseLog 등의 함수로 분리하는 것도 좋아보입니다~~

import { tap } from 'rxjs';

@Injectable()
export class HttpLoggingInterceptor implements NestInterceptor {
Copy link
Collaborator

Choose a reason for hiding this comment

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

🟢
클래스명과 파일명을 일치시키면 코드를 찾아가기가 좋을 것 같습니다.
그리고, import 시에도 더 용이할 것 같습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

아 이 부분은 주의해야겠어요. 항상 파일이랑 클래스 이름 일치를 확인을 못하네요. 중간에 이름을 한번 바꾼거라..

@PMtHk
Copy link
Collaborator

PMtHk commented Nov 10, 2024

아 추가로!
정한님도 리포지토리 포크 후 개발하고 계신 것 같습니다.
이 경우, 테스트하기 위해 브랜치 조회가 안되는 문제가 있습니다.

괜찮으시다면 하시던 작업 이후로는 레포지토리 클론 후 작업해주시면 감사하겠습니다!!

@@ -2,9 +2,12 @@ import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { DataSource, DataSourceOptions } from 'typeorm';
import { ConfigModule } from '@nestjs/config';
import { APP_FILTER, APP_INTERCEPTOR } from '@nestjs/core';
import { TypeormConfig } from '../config/typeorm.config';
Copy link
Collaborator

Choose a reason for hiding this comment

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

단순 궁금증인데,
상대 경로 나열되면 불편하진 않으신가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

절대 경로로 변경하는게 보기에 더 좋을까요? 이때까지 크게 불편함을 크게 느끼지 못해서 계속 사용하고 있었는데 수정해야겠네요

@jjeonghak jjeonghak merged commit 4d3dfad into boostcampwm-2024:dev Nov 10, 2024
2 checks passed
@jjeonghak jjeonghak deleted the feat/#2 branch November 13, 2024 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE 서버 작업 Config 환경 설정, 기타 작업
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants