question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] How to use Pino for entire application with configuration options?

See original GitHub issue

Hi!

First of all, thanks for this module, it is really appreciated.

I am trying to use Pino Logger throughout the application; perhaps I am wrong about it, but what I am doing is to add the following code to app.module.ts:

@Module({
    imports: [
        ConfigModule.forRoot(),
        LoggerModule.forRoot({
            pinoHttp: { prettyPrint: true, useLevelLabels: true }, // <--
        }),
        // ...
    ],
    // ...
})
export class AppModule {}

And, in main.ts:

import { NestFactory } from '@nestjs/core';
import { Logger } from 'nestjs-pino';

async function bootstrap() {
  // Create the application.
  const app = await NestFactory.create(AppModule, { logger: false });

  // Get Pino Logger instance.
  const logger = app.get(Logger);

  // Use Pino as the main logger!
  app.useLogger(logger);

  // Start the server!
  await app.listen(3030);
}

// Initialize application!
bootstrap();

The issue is that, if I import LoggerModule and call forRoot (or forRootAsync by injecting ConfigService etc), without any Pino options (prettyPrint or useLevelLabels) it works perfectly, however when adding even one option, it hangs the entire application without even booting!

  1. Is this the way to use the Logger throughout the Application?
  2. If it is, am I providing configuration options in a wrong format?

I would like to use Pino as the main logging system for the entire application, no exclusions.

I am using NestJS v7.

Again, thanks for this library! And thanks in advance for any commentary this might receive 😃

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
humbertowoodycommented, Jul 21, 2020

Thank you very much @iamolegga ! Sorry to miss that part of the docs! Guess I just read this package ones and not the pino itself ones! Really sorry about this. Thanks for quick response and guidance 😃

3reactions
iamoleggacommented, Jul 18, 2020

Hey @humbertowoody just found the problem. When using prettyPrint property you need extra installation of pino-pretty as it said in docs 🙂

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Complete Guide to Pino Logging in Node.js - Better Stack
In this tutorial, you will learn how to create a logging service for your application with Pino. We'll discuss many of the features...
Read more >
How to Implement Logging in a Node.js Application With Pino ...
This tutorial is about implementing logging in a Node.js application using Pino-logger. With logging, you can store every bit of information ...
Read more >
Logging with Pino and AsyncLocalStorage in Node.js
In this post, you can learn what a logging library is, why you should use it, and how to log with Pino and...
Read more >
Create Industry-Standard Logger for Node.js Using Pino
A guide to creating an industry-standard logger for Node.js using Pino. ... This article is going to cover the use of the Pino...
Read more >
How to avoid the entire request being logged every time using ...
The gist is to override the serializer for the request by including the following configuration option when initializing pino
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found