Reset logs

This commit is contained in:
LeoMortari
2025-09-15 01:29:22 -03:00
parent b8c70d81c8
commit 741a762620
3 changed files with 6 additions and 81 deletions

View File

@@ -1,6 +1,5 @@
import { Module, MiddlewareConsumer } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { LoggerModule } from 'nestjs-pino';
import { PrismaModule } from './prisma/prisma.module';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@@ -14,28 +13,7 @@ import { AuthController } from './auth/auth.controller';
@Module({
imports: [
ConfigModule.forRoot({
isGlobal: true,
}),
LoggerModule.forRootAsync({
useFactory: () => ({
pinoHttp: {
level: process.env.NODE_ENV === 'production' ? 'info' : 'debug',
transport:
process.env.NODE_ENV !== 'production'
? {
target: 'pino-pretty',
options: {
colorize: true,
levelFirst: true,
translateTime: 'SYS:HH:MM:ss.l',
ignore: 'pid,hostname',
},
}
: undefined,
},
}),
}),
ConfigModule.forRoot(),
PrismaModule,
VideosModule,
AuthModule,

View File

@@ -1,63 +1,13 @@
import {
ClassSerializerInterceptor,
Logger,
ValidationPipe,
} from '@nestjs/common';
import { ClassSerializerInterceptor } from '@nestjs/common';
import { NestFactory, Reflector } from '@nestjs/core';
import { AppModule } from './app.module';
import { Logger as PinoLogger } from 'nestjs-pino';
async function bootstrap() {
// Create app with default logger first
const app = await NestFactory.create(AppModule, {
logger: ['error', 'warn', 'log', 'debug', 'verbose'],
});
// Then set up Pino logger
const pinoLogger = app.get(PinoLogger, { strict: false });
if (pinoLogger) {
app.useLogger(pinoLogger);
}
const logger = app.get(Logger);
const app = await NestFactory.create(AppModule);
const reflector = app.get(Reflector);
// Global pipes and interceptors
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
transform: true,
forbidNonWhitelisted: true,
}),
);
app.useGlobalInterceptors(new ClassSerializerInterceptor(reflector));
app.useGlobalInterceptors(
new ClassSerializerInterceptor(reflector, {
excludePrefixes: ['_'],
}),
);
// Enable CORS
app.enableCors({
origin: process.env.CORS_ORIGIN || '*',
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
credentials: true,
});
// Start the application
const port = process.env.PORT || 3000;
await app.listen(port);
logger.log(`🚀 Application is running on port: ${port}`);
logger.log(`📡 Environment: ${process.env.NODE_ENV || 'development'}`);
if (process.env.NODE_ENV === 'development') {
logger.debug('🔧 Debug mode is enabled');
}
await app.listen(process.env.PORT ?? 3000);
}
bootstrap().catch((error) => {
// Use console.error here since the logger might not be available
console.error('Failed to start application', error);
process.exit(1);
});
void bootstrap();