feat: add logging
This commit is contained in:
+38
-2
@@ -1,7 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { LoggerModule } from 'nestjs-pino';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { validateEnv } from './config/env.validation';
|
||||
import { LoggingModule } from './common/logging/logging.module';
|
||||
import { Environment, validateEnv } from './config/env.validation';
|
||||
import { PrismaModule } from './prisma/prisma.module';
|
||||
import { TbankConnectionModule } from './tbank/tbank-connection.module';
|
||||
|
||||
@@ -11,6 +14,39 @@ import { TbankConnectionModule } from './tbank/tbank-connection.module';
|
||||
isGlobal: true,
|
||||
validate: validateEnv,
|
||||
}),
|
||||
LoggerModule.forRootAsync({
|
||||
inject: [ConfigService],
|
||||
useFactory: (config: ConfigService<Environment, true>) => ({
|
||||
pinoHttp: {
|
||||
level: config.getOrThrow('LOG_LEVEL'),
|
||||
messageKey: 'message',
|
||||
autoLogging: false,
|
||||
genReqId: (request: unknown, response) => {
|
||||
const existingId = (request as { id?: unknown }).id;
|
||||
const requestId =
|
||||
typeof existingId === 'string' ? existingId : randomUUID();
|
||||
response.setHeader('X-Request-ID', requestId);
|
||||
return requestId;
|
||||
},
|
||||
redact: [
|
||||
'req.headers.authorization',
|
||||
'req.headers.cookie',
|
||||
'req.body',
|
||||
],
|
||||
serializers: {
|
||||
req: (request: unknown) => {
|
||||
const value = request as { id?: unknown; method?: unknown };
|
||||
return {
|
||||
id: typeof value.id === 'string' ? value.id : undefined,
|
||||
method:
|
||||
typeof value.method === 'string' ? value.method : undefined,
|
||||
};
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}),
|
||||
LoggingModule,
|
||||
PrismaModule,
|
||||
AuthModule,
|
||||
TbankConnectionModule,
|
||||
|
||||
Reference in New Issue
Block a user