Skip to content

Commit

Permalink
feat: vary logging based on env
Browse files Browse the repository at this point in the history
  • Loading branch information
lukejianu committed Oct 22, 2023
1 parent 0a4c3d5 commit f62ec4e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/api-v2/ormconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 11 additions & 2 deletions packages/api-v2/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ClassSerializerInterceptor,
LogLevel,
LoggerService,
ValidationPipe,
} from "@nestjs/common";
Expand All @@ -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,
Expand Down Expand Up @@ -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();

0 comments on commit f62ec4e

Please sign in to comment.