Skip to content

Commit

Permalink
dependency : add pino logger
Browse files Browse the repository at this point in the history
  • Loading branch information
kangjuhyup committed Dec 26, 2024
1 parent b2db7d1 commit ac84bd4
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 8 deletions.
7 changes: 6 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
yarnPath: .yarn/releases/yarn-4.5.0.cjs
nodeLinker : pnp
nodeLinker: pnp
packageExtensions:
nestjs-pino@*:
dependencies:
pino: '*'
rxjs: '*'
4 changes: 4 additions & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@
"jsonwebtoken": "^9.0.2",
"jwks-rsa": "^3.1.0",
"mysql2": "^3.11.3",
"nestjs-pino": "^4.2.0",
"node-imap": "^0.9.6",
"passport": "^0.7.0",
"passport-google-oauth20": "^2.0.0",
"passport-jwt": "^4.0.1",
"pino": "^9.6.0",
"pino-http": "^10.3.0",
"pino-pretty": "^13.0.0",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
"swagger-ui-express": "^5.0.1",
Expand Down
20 changes: 20 additions & 0 deletions packages/server/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { AuthModule } from './domain/auth/auth.module';
import { UserModule } from './domain/user/user.module';
import { DatabaseModule } from './database/database.module';
import { StorageModule } from './storage/storage.module';
import { LoggerModule } from 'nestjs-pino';

export const routers = [
AuthModule.forRootAsync({
Expand Down Expand Up @@ -57,6 +58,25 @@ export const modules = [
},
inject: [ConfigService],
}),
LoggerModule.forRootAsync({
inject: [ConfigService],
useFactory: (config: ConfigService) => ({
pinoHttp: {
level: config.get<string>('LOG_LEVEL', 'info'),
transport:
process.env.NODE_ENV !== 'production'
? {
target: 'pino-pretty',
options: {
colorize: true,
singleLine: true,
translateTime: 'SYS:standard',
},
}
: undefined,
},
}),
}),
].filter(Boolean);

@Module({
Expand Down
4 changes: 1 addition & 3 deletions packages/server/src/domain/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { UserRefreshStrategy } from '@app/jwt/strategy/user.refresh.strategy';
import { AuthFacade } from './auth.facade';
import { MailService } from './service/mail.service';
import { SessionService } from './service/session.service';
import { GoogleStrategy } from '@app/jwt/strategy/google.strategy';
import { GoogleService } from '../google/google.service';
import { HttpModule } from '@nestjs/axios';

Expand All @@ -20,7 +19,6 @@ interface AuthModuleAsyncOptions {
useFactory: (...args: any[]) => { secret: string; expiresIn: string };
isGlobal?: boolean;
}
//TODO : Refresh 토큰 추가
@Module({})
export class AuthModule {
static forRootAsync(options: AuthModuleAsyncOptions): DynamicModule {
Expand Down Expand Up @@ -64,7 +62,7 @@ export class AuthModule {
},
inject: [UserService, ...(options.inject || [])],
},
GoogleStrategy,
// GoogleStrategy,
AuthService,
MailService,
GoogleService,
Expand Down
7 changes: 4 additions & 3 deletions packages/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ValidationPipe } from '@nestjs/common';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { Logger } from 'nestjs-pino';

async function bootstrap() {
const app = await NestFactory.create(AppModule);

const app = await NestFactory.create(AppModule, {bufferLogs : true});
app.useLogger(app.get(Logger));
app.enableCors({
origin : '*'
})
Expand All @@ -24,7 +25,7 @@ async function bootstrap() {
.addTag('invite')
.addBearerAuth(
{ type: 'http', scheme: 'bearer', bearerFormat: 'JWT' },
'access-token', // 이 이름은 Swagger UI에서 인증 키 이름으로 사용됩니다.
'access-token',
)
.build();

Expand Down
Loading

0 comments on commit ac84bd4

Please sign in to comment.