Skip to content

Commit

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

async function bootstrap() {
// configure custom logger
// TODO: Update context.
// 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, {
Expand Down Expand Up @@ -60,4 +61,12 @@ function logLevels(env: string): LogLevel[] {
return ["log", "error", "warn", "debug"];
}

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 5bbbdb0

Please sign in to comment.