Skip to content

Commit bfb99ba

Browse files
committed
refactor: use logger
1 parent 4d42a43 commit bfb99ba

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

apps/api/src/main.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,30 @@
33
import path from 'node:path';
44

55
import { ValidationPipe } from '@douglasneuroinformatics/libnest/core';
6-
import { type LogLevel, VersioningType } from '@nestjs/common';
6+
import { JSONLogger } from '@douglasneuroinformatics/libnest/logging';
7+
import { VersioningType } from '@nestjs/common';
78
import { NestFactory } from '@nestjs/core';
8-
import { type NestExpressApplication } from '@nestjs/platform-express';
9+
import type { NestExpressApplication } from '@nestjs/platform-express';
910
import { json } from 'express';
1011

1112
import { AppModule } from './app.module';
1213
import { ConfigurationService } from './configuration/configuration.service';
1314
import { setupDocs } from './docs';
1415

1516
async function bootstrap() {
16-
// This hacky type assertion is needed due to issue with linked dependency
17-
const app = (await NestFactory.create(AppModule)) as any as NestExpressApplication;
17+
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
18+
logger: false
19+
});
1820
app.enableShutdownHooks();
1921

2022
const configurationService = app.get(ConfigurationService);
21-
const logLevels: LogLevel[] = ['error', 'fatal', 'log', 'warn'];
22-
if (configurationService.get('DEBUG')) {
23-
console.log("Enabled 'debug' logs");
24-
logLevels.push('debug');
25-
}
26-
if (configurationService.get('VERBOSE')) {
27-
console.log("Enabled 'verbose' logs");
28-
logLevels.push('verbose');
29-
}
30-
31-
console.log({ debug: configurationService.get('DEBUG') });
32-
33-
app.useLogger(logLevels);
23+
24+
app.useLogger(
25+
new JSONLogger(null, {
26+
debug: configurationService.get('DEBUG'),
27+
verbose: configurationService.get('VERBOSE')
28+
})
29+
);
3430

3531
app.enableCors();
3632
app.enableVersioning({

0 commit comments

Comments
 (0)