Skip to content

Commit

Permalink
Merge pull request #641 from sandboxnu/luke/reduce-logging
Browse files Browse the repository at this point in the history
feat: vary logging based on env
  • Loading branch information
lukejianu authored Oct 29, 2023
2 parents 559de8e + bafdad9 commit 0c9c7cf
Showing 1 changed file with 11 additions and 2 deletions.
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,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,
Expand Down Expand Up @@ -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();

0 comments on commit 0c9c7cf

Please sign in to comment.