From f62ec4ebd83aa760db89c4404b64db70efa07cc7 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/ormconfig.ts | 4 +++- packages/api-v2/src/main.ts | 13 +++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/api-v2/ormconfig.ts b/packages/api-v2/ormconfig.ts index bfe899ba8..ef71ed03f 100644 --- a/packages/api-v2/ormconfig.ts +++ b/packages/api-v2/ormconfig.ts @@ -3,7 +3,9 @@ import { config } from "dotenv"; import { Plan } from "./src/plan/entities/plan.entity"; import { Student } from "./src/student/entities/student.entity"; -config({ path: `.env.${process.env.NODE_ENV}.local` }); + +// TODO: Probably remove the override. +config({ path: `.env.${process.env.NODE_ENV}.local`, override: true}); const ormconfig: TypeOrmModuleOptions = { type: "postgres", diff --git a/packages/api-v2/src/main.ts b/packages/api-v2/src/main.ts index 2b3cfb3c1..588749fcb 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,8 @@ import * as cookieParser from "cookie-parser"; async function bootstrap() { // configure custom logger - const graduateLogger: LoggerService = new GraduateLogger(); - graduateLogger.setLogLevels(["log", "error", "warn", "debug"]); + // TODO: Update context (first param to logger). + const graduateLogger: LoggerService = new GraduateLogger("graduatenu", {logLevels: logLevels(process.env.NODE_ENV)}); const app = await NestFactory.create(AppModule, { logger: graduateLogger, @@ -51,4 +52,12 @@ async function bootstrap() { await app.listen(configService.get("PORT")); } +function logLevels(env: string): LogLevel[] { + // TODO: Is there a constant declared somewhere for this? + if (env === "production") { + return ["error", "warn"]; + } + return ["log", "error", "warn", "debug"]; +} + bootstrap();