Skip to content

Commit

Permalink
Merge pull request #57 from plus-tdd/feature/counseling
Browse files Browse the repository at this point in the history
로깅 형식 변경
  • Loading branch information
codeing999 authored Jul 26, 2023
2 parents 30e28ba + 38b3927 commit e999577
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class AppController {
getHello(): { statusCode: number; data: string } {
const logger = new Logger('application.app.controller');
console.log('???');
logger.info('안녕하세요', '재철대문입니다.');
logger.info('안녕하세요', '대문입니다.');
const data = this.appService.getHello();
return { statusCode: 200, data };
}
Expand Down
14 changes: 6 additions & 8 deletions src/logger/logger.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@ export class LoggerMiddleware implements NestMiddleware {
const { method, originalUrl: url, params, query, body, headers } = req;

const originalSend = res.send;
res.send = function (body) {
const responseBody = body instanceof Object ? JSON.stringify(body) : body;
const { method, originalUrl: url } = req;
res.send = function (responseBody) {
const statusCode = res.statusCode;

// 응답 전송
res.send = originalSend;
res.send(body);
res.send(responseBody);

// 로그 남기기
this.logger.info(
`${method} ${url} StatusCode: ${statusCode}\n[REQUEST] \nParams: ${JSON.stringify(
`${method} ${url} ${statusCode}\n[REQUEST] \nParams: ${JSON.stringify(
params,
)} \nQuery: ${JSON.stringify(query)} \nBody: ${JSON.stringify(
)}Query: ${JSON.stringify(query)}Body: ${JSON.stringify(
body,
)} \nHeaders: ${JSON.stringify(
)}Headers: ${JSON.stringify(
headers,
)} \n[RESPONSE] \n \nBody: ${responseBody}`,
)}[RESPONSE]\nStatus:${statusCode}\nBody: ${responseBody}`,
);
}.bind(this);

Expand Down

0 comments on commit e999577

Please sign in to comment.