Skip to content

Commit

Permalink
🩹 로깅 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
codeing999 committed Oct 12, 2023
1 parent 7731f78 commit acea538
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 31 deletions.
4 changes: 1 addition & 3 deletions src/__tests__/counseling/counseling.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import path from 'path';
// Controller ( Api Route ) 에서 서비스를 호출한다 = Backend
// -> 그래서 서비스 UnitTest 에 대해서는 nestjs/testing 의 TestingModule 을 사용하지 않는 게 더 좋은 구조라고 생각함. - by 허재
class TestCounselingRepository implements CounselingRepository {
async registerCounselingHistory(
info: CounselingCreateInfo,
): Promise<Counseling> {
async registerCounseling(info: CounselingCreateInfo): Promise<Counseling> {
return {
id: 1,
hospitalName: '어쩌라고',
Expand Down
2 changes: 1 addition & 1 deletion src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { AlarmModule } from './module/alarm/alarm.module';
import { AlarmServiceImpl } from './module/alarm/alarm.service';
import { DoctorModule } from './module/doctor/doctor.module';
import { DoctorEntity } from './module/doctor/data/doctor.entity';
import { LoggerMiddleware } from './logger/logger.middleware';
import { LoggerMiddleware } from './common/middlewares/logger.middleware';

// Module 설명 : express에서는 router위주의 설계였다면, nest에서는 module위주의 설계를 한다
// 기능별로 module을 만들어서 여기에 다 넣어줄거임 - nest가 module간의 연결된걸 파악해서 한번에 실행해줌
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';
import Logger from './../logger';
import Logger from '../../logger';

@Injectable()
export class LoggerMiddleware implements NestMiddleware {
Expand All @@ -19,21 +19,24 @@ export class LoggerMiddleware implements NestMiddleware {
// 로그 남기기
this.logger.info(
`${method} ${url} ${statusCode}\n ========================[REQUEST]========================\n` +
`Params: ${JSON.stringify(params, null, 2)}\n` +
`Query: ${JSON.stringify(query, null, 2).replace(/,/g, ',\n')}\n` +
`Body: { \n` +
Object.keys(body)
.map((key) => ` "${key}": "${body[key]}"`)
.join(",\n") +
`\n}\n` +
`Headers: {\n` +
Object.keys(headers)
.map((key) => ` "${key}": "${headers[key]}"`)
.join(",\n") +
`\n}\n` +
`========================[RESPONSE]========================\n` +
`Status:${statusCode}\n` +
`Body: ${JSON.stringify(JSON.parse(responseBody), null, '').replace(/,/g, ',\n')}`
`Params: ${JSON.stringify(params, null, 2)}\n` +
`Query: ${JSON.stringify(query, null, 2).replace(/,/g, ',\n')}\n` +
`Body: { \n` +
Object.keys(body)
.map((key) => ` "${key}": "${body[key]}"`)
.join(',\n') +
`\n}\n` +
`Headers: {\n` +
Object.keys(headers)
.map((key) => ` "${key}": "${headers[key]}"`)
.join(',\n') +
`\n}\n` +
`========================[RESPONSE]========================\n` +
`Status:${statusCode}\n` +
`Body: ${JSON.stringify(JSON.parse(responseBody), null, '').replace(
/,/g,
',\n',
)}`,
);
}.bind(this);

Expand Down
7 changes: 0 additions & 7 deletions src/logger/logger.middleware.spec.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import Logger from './logger';
import { HttpExceptionFilter } from './http-exception.filter';
import { HttpExceptionFilter } from './common/exceptions/http-exception.filter';
import * as moment from 'moment-timezone';
import express from 'express';
import { join } from 'path';
Expand Down Expand Up @@ -32,7 +32,6 @@ async function bootstrap() {
await app.listen(port);
console.log(`listening on port ${port}`);


if (module.hot) {
module.hot.accept();
module.hot.dispose(() => app.close());
Expand Down
4 changes: 2 additions & 2 deletions src/module/counseling/api/counseling.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import { Counseling } from '../domain/counseling.model';

@Controller('counseling')
export class CounselingController {
private mapper: CounselingMapper;
private response: Response;

constructor(private readonly counselingService: CounselingService) {
this.mapper = new CounselingMapper();
this.response = new Response();
}

private mapper: CounselingMapper;

@UseGuards(JwtAuthGuard)
@ApiOperation({ summary: '진료 예약' })
@Post()
Expand Down

0 comments on commit acea538

Please sign in to comment.