Skip to content

Commit 5d462c2

Browse files
committed
서버시간 고정되는게 아니라 타임존 문제 해결
1 parent e640e45 commit 5d462c2

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"dotenv": "^16.3.1",
4242
"fastify-swagger": "^5.2.0",
4343
"moment": "^2.29.4",
44+
"moment-timezone": "^0.5.43",
4445
"mysql2": "^3.4.1",
4546
"nest-winston": "^1.9.3",
4647
"passport": "^0.6.0",

src/logger.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import {
44
PutLogEventsCommand,
55
} from '@aws-sdk/client-cloudwatch-logs';
66
import * as process from 'process';
7-
import moment from 'moment';
7+
const moment = require('moment-timezone');
88

99
const { createLogger, format, transports } = winston;
1010
const { combine, timestamp, colorize, printf, simple, json, logstash } =
1111
winston.format;
12+
const now = moment().format('YYYY-MM-DD HH:mm:ss');
1213

1314
export default class Logger {
1415
private logger: winston.Logger;
@@ -66,7 +67,6 @@ export default class Logger {
6667
}
6768

6869
public info(msg: string, metadata: string = '') {
69-
const now = moment().format('YYYY-MM-DD HH:mm:ss');
7070
this.logger.info(msg);
7171
if (this.is_production) {
7272
const info = {
@@ -80,7 +80,6 @@ export default class Logger {
8080
}
8181
}
8282
public error(errMsg: string, metadata: string = '') {
83-
const now = moment().format('YYYY-MM-DD HH:mm:ss');
8483
this.logger.error(errMsg);
8584
if (this.is_production) {
8685
const info = {
@@ -97,7 +96,6 @@ export default class Logger {
9796
this.logger.debug(debugMsg);
9897
}
9998
public warn(warnMsg: string, metadata: string = '') {
100-
const now = moment().format('YYYY-MM-DD HH:mm:ss');
10199
this.logger.warn(warnMsg);
102100
if (this.is_production) {
103101
const info = {

src/main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import { NestFactory } from '@nestjs/core';
22
import { AppModule } from './app.module';
33
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
44
import Logger from './logger';
5+
const moment = require('moment-timezone');
56

67
declare const module: any;
78

89
async function bootstrap() {
910
const logger = new Logger('application.main');
11+
moment.tz.setDefault('Asia/Seoul'); // 서버 시간대를 전역으로 아시아 서울로 설정한다. 매번 리전 안정해줘도됨
1012
const app = await NestFactory.create(AppModule);
1113
const port = process.env.PORT || 3000;
1214
const config = new DocumentBuilder()

0 commit comments

Comments
 (0)