Skip to content

Commit

Permalink
fix: disable internal logs
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiin committed Aug 30, 2024
1 parent 0275e34 commit 1600439
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/lib/pino/internal.logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ConsoleLogger } from '@nestjs/common'

/**
* A custom logger that disables all logs emitted by calling `log` method if
* they use one of the following contexts:
* - `InstanceLoader`
* - `RoutesResolver`
* - `RouterExplorer`
* - `NestFactory`
*/
export class InternalDisabledLogger extends ConsoleLogger {
static contextsToIgnore = [
'InstanceLoader',
'RoutesResolver',
'RouterExplorer',
'NestFactory'
]

log(message: any, context?: string): void {
if ((context != null) && !InternalDisabledLogger.contextsToIgnore.includes(context)) {
super.log(message,context)
}
}
}
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import compression from "compression";
import helmet from "helmet";
import { I18nValidationExceptionFilter } from "nestjs-i18n";
import { LoggerErrorInterceptor } from "nestjs-pino";
import { InternalDisabledLogger } from "@lib/pino/inter.logger";
import { AppModule } from "./modules/app.module";
import { SocketIOAdapter } from "./socket-io.adapter";

Expand All @@ -27,8 +28,10 @@ async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(
AppModule,
new ExpressAdapter(),

{
snapshot: true,
logger: new InternalDisabledLogger()
},
);

Expand Down

0 comments on commit 1600439

Please sign in to comment.