nestjs-pino: [BUG] System logs skipped on startup
Hi,
I am using pino with configuration as illustrated below:
// app.module.ts
import { Module } from '@nestjs/common';
import { LoggerModule } from 'nestjs-pino';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import * as pino from 'pino';
const logger = pino({
level: process.env.NODE_ENV !== 'prod' ? 'debug' : 'info',
},pino.destination({
minLength: 4096,
sync: false,
}));
setInterval(function() {
logger.flush();
}, 5000).unref();
@Module({
imports: [
LoggerModule.forRoot({
pinoHttp: {
logger,
autoLogging: true,
serializers: {
err: pino.stdSerializers.err,
req: r => {
return {
id: r.id,
method: r.method,
url: r.url,
};
},
res: pino.stdSerializers.res,
}
},
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
and
// main.ts
import { NestFactory } from '@nestjs/core';
import { Logger } from 'nestjs-pino';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule, { logger: false });
app.useLogger(app.get(Logger));
await app.listen(3000);
}
bootstrap();
But the logging output missed the system logging part.
> nest start --watch
[10:11:49 PM] Starting compilation in watch mode...
[10:11:53 PM] Found 0 errors. Watching for file changes.
{"level":30,"time":1604671913986,"pid":28435,"hostname":"2070iMac","context":"RoutesResolver","msg":"AppController {}:"}
{"level":30,"time":1604671913987,"pid":28435,"hostname":"2070iMac","context":"RouterExplorer","msg":"Mapped {, GET} route"}
{"level":30,"time":1604671913989,"pid":28435,"hostname":"2070iMac","context":"NestApplication","msg":"Nest application successfully started"}
It is expected to output as many as system logging output, which has logging form modules like NestFactory and InstanceLoader. Below is the output from the default logger.
[10:33:59 PM] Starting compilation in watch mode...
[10:34:00 PM] Found 0 errors. Watching for file changes.
[Nest] 30928 - 11/06/2020, 10:34:01 PM [NestFactory] Starting Nest application...
[Nest] 30928 - 11/06/2020, 10:34:01 PM [InstanceLoader] LoggerModule dependencies initialized +15ms
[Nest] 30928 - 11/06/2020, 10:34:01 PM [InstanceLoader] LoggerCoreModule dependencies initialized +1ms
[Nest] 30928 - 11/06/2020, 10:34:01 PM [InstanceLoader] AppModule dependencies initialized +0ms
[Nest] 30928 - 11/06/2020, 10:34:01 PM [RoutesResolver] AppController {}: +6ms
[Nest] 30928 - 11/06/2020, 10:34:01 PM [RouterExplorer] Mapped {, GET} route +1ms
[Nest] 30928 - 11/06/2020, 10:34:01 PM [NestApplication] Nest application successfully started +4ms
Here are some sample code to reproduce this issue: https://github.com/wuminqi/example-pino-nestjs
Can you kindly offer a help on this?
Thanks.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 7
- Comments: 20 (10 by maintainers)
@StevenLangbroek please add the link to the minimal example repo. I’ll reopen this issue then
Hi, thanks for your kindly reply.
I realize this issue as I misconfigured TypeORM and all the error logs from [TypeOrmModule] is swallowed. I have no idea what exception it is.
I updated the sample repo by adding typeorm and some invalid configurations, link.
Using nestjs-pino, the startup output:
Using default logger, the startup output: