Skip to content

Commit 0d335ae

Browse files
authored
Merge pull request #20 from DevKor-github/infra/logging
Infra/logging 오류 수정
2 parents 699b50a + 9c1df1d commit 0d335ae

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

src/log/log.controller.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
1-
import { Controller, Get, Res, StreamableFile } from '@nestjs/common';
1+
import {
2+
Controller,
3+
Get,
4+
Param,
5+
Query,
6+
Res,
7+
StreamableFile,
8+
} from '@nestjs/common';
29
import { LogService } from './log.service';
310
import { ApiOperation, ApiTags } from '@nestjs/swagger';
411
import { Public } from 'src/auth/auth.guard';
12+
import { string } from 'joi';
513

614
@ApiTags('Log')
715
@Controller('log')
816
export class LogController {
917
constructor(private readonly logService: LogService) {}
1018

19+
@Public()
20+
@Get('/test')
21+
getTest() {
22+
console.log('test');
23+
return 'test';
24+
}
25+
1126
@ApiOperation({ summary: '로그 파일 확인' })
1227
@Public()
1328
@Get()
14-
getLog(): StreamableFile {
15-
return this.logService.getLogs();
29+
getLog(@Query('pw') pw: string): StreamableFile {
30+
return this.logService.getLogs(pw);
1631
}
1732

1833
@ApiOperation({ summary: '에러 로그 확인' })
1934
@Public()
2035
@Get('/error')
21-
getErrorLog(): StreamableFile {
22-
return this.logService.getErrorLogs();
36+
getErrorLog(@Query('pw') pw: string): StreamableFile {
37+
return this.logService.getErrorLogs(pw);
2338
}
2439
}

src/log/log.service.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { Injectable, NotFoundException, StreamableFile } from '@nestjs/common';
1+
import {
2+
Injectable,
3+
NotFoundException,
4+
StreamableFile,
5+
UnauthorizedException,
6+
} from '@nestjs/common';
27
import { ConfigService } from '@nestjs/config';
38
import { createReadStream, existsSync } from 'fs';
49

@@ -10,15 +15,22 @@ export class LogService {
1015
this.logFilePath = this.configService.get('LOG_FILE_PATH');
1116
this.errorLogFilePath = this.configService.get('ERROR_LOG_FILE_PATH');
1217
}
13-
getLogs(): StreamableFile {
18+
getLogs(pw: string): StreamableFile {
19+
if (pw !== this.configService.get('LOG_PW')) {
20+
throw new UnauthorizedException('로그 파일을 확인할 권한이 없습니다.');
21+
}
1422
if (!existsSync(this.logFilePath)) {
1523
throw new NotFoundException('로그 파일이 존재하지 않습니다.');
1624
}
1725
return new StreamableFile(createReadStream(this.logFilePath), {
1826
type: 'text/plain',
1927
});
2028
}
21-
getErrorLogs(): StreamableFile {
29+
30+
getErrorLogs(pw: string): StreamableFile {
31+
if (pw != this.configService.get('LOG_PW')) {
32+
throw new UnauthorizedException('로그 파일을 확인할 권한이 없습니다.');
33+
}
2234
if (!existsSync(this.logFilePath)) {
2335
throw new NotFoundException('로그 파일이 존재하지 않습니다.');
2436
}

0 commit comments

Comments
 (0)