-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: no auth 버그 -> password 주석 해제 * feat: 로그에 한국 시간대 추가 * feat: 로그파일이 dist 내부에 존재해 한 단계 위로 옮겨줌. * feat: 응답로그는 interceptor에서 처리하도록 로직 수정 * feat: 로그 인터셉터 app.module.ts 프로바이더에 추가
- Loading branch information
1 parent
7ae37bb
commit d047b41
Showing
5 changed files
with
58 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
CallHandler, | ||
ExecutionContext, | ||
Injectable, | ||
NestInterceptor, | ||
} from '@nestjs/common'; | ||
import { Observable } from 'rxjs'; | ||
import { tap } from 'rxjs/operators'; | ||
import { WinstonModule } from 'nest-winston'; | ||
import { winstonConfig } from '../../utils/winston.config'; | ||
|
||
@Injectable() | ||
export class LoggingInterceptor implements NestInterceptor { | ||
private readonly logger = WinstonModule.createLogger(winstonConfig); | ||
|
||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> { | ||
const ctx = context.switchToHttp(); | ||
const request = ctx.getRequest(); | ||
const response = ctx.getResponse(); | ||
const startTime = request['startTime']; | ||
const reqBody = request['reqBody']; | ||
|
||
return next.handle().pipe( | ||
tap((data) => { | ||
const endTime = Date.now(); | ||
const duration = endTime - startTime; | ||
const { method, originalUrl, ip } = request; | ||
const { statusCode } = response; | ||
const startTimeString = new Date(startTime).toLocaleString('ko-KR', { | ||
timeZone: 'Asia/Seoul', | ||
}); | ||
|
||
this.logger.log({ | ||
level: 'info', | ||
message: `${startTimeString} - ${method} ${originalUrl} - Status: ${statusCode} - IP: ${ip} - Duration: ${duration}ms - Request Body: ${JSON.stringify( | ||
reqBody, | ||
)} - Response Body: ${JSON.stringify(data)}`, | ||
}); | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters