From bafdad9b7c01bc391f48d8a3f8a08c025b904b83 Mon Sep 17 00:00:00 2001 From: lukejianu <71729102+lukejianu@users.noreply.github.com> Date: Sun, 22 Oct 2023 16:38:02 -0400 Subject: [PATCH] feat: vary logging based on env --- packages/api-v2/src/main.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/api-v2/src/main.ts b/packages/api-v2/src/main.ts index 2b3cfb3c1..86120b93f 100644 --- a/packages/api-v2/src/main.ts +++ b/packages/api-v2/src/main.ts @@ -1,5 +1,6 @@ import { ClassSerializerInterceptor, + LogLevel, LoggerService, ValidationPipe, } from "@nestjs/common"; @@ -12,8 +13,9 @@ import * as cookieParser from "cookie-parser"; async function bootstrap() { // configure custom logger - const graduateLogger: LoggerService = new GraduateLogger(); - graduateLogger.setLogLevels(["log", "error", "warn", "debug"]); + const graduateLogger: LoggerService = new GraduateLogger("graduatenu", { + logLevels: logLevels(process.env.NODE_ENV), + }); const app = await NestFactory.create(AppModule, { logger: graduateLogger, @@ -51,4 +53,11 @@ async function bootstrap() { await app.listen(configService.get("PORT")); } +function logLevels(env: string): LogLevel[] { + if (env === "production") { + return ["error", "warn"]; + } + return ["log", "error", "warn", "debug"]; +} + bootstrap();