[QUESTION] Extend PinoLogger class

See original GitHub issue

Hi guys! I would like to extend the Pino logger to be able to inject my own business logic in some cases (for example logger.error).

So decided to build a logger module on top of nestjs-pino.

Here are my two files

logger.service.ts

import { Injectable } from '@nestjs/common';
import { PinoLogger } from 'nestjs-pino';

@Injectable()
export class LoggerService extends PinoLogger {
  error(message: any, trace?: string, context?: string, ...args: any[]) {
    // My business logic here
    super.error(message, trace);
  }
}

logger.module.ts

import { Global, Module } from '@nestjs/common';
import { LoggerService } from './logger.service';
import { LoggerModule as PinoModule } from 'nestjs-pino';

@Global()
@Module({
  imports: [PinoModule.forRoot()],
  providers: [LoggerService],
  exports: [LoggerService],
})
export class LoggerModule {}

I am importing the module in app.module.ts. My issue is when I start the application, I got this error at module initialization.

Error: Nest can't resolve dependencies of the LoggerService (?). Please make sure that the argument pino-params at index [0] is available in the LoggerModule context.

Potential solutions:
- If pino-params is a provider, is it part of the current LoggerModule?
- If pino-params is exported from a separate @Module, is that module imported within LoggerModule?
  @Module({
    imports: [ /* the Module containing pino-params */ ]
  })

I cannot figured out why I have this message, I am well imported the PinoModule in the loggerModule.

Thanks for any help đŸ˜¸

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
jdt6commented, Mar 24, 2021

until PR gets merged, @iamolegga, or @dguyonvarch what is the work around for adding a wrapper around the Logger?

2reactions
iamoleggacommented, Mar 24, 2021

@dguyonvarch feel free to open pr for this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extended Class methods are not exposed - Stack Overflow
Note: I am a maintainer of Pino. The function returned by require('pino') is a factory function not a "constructor" function.
Read more >
nestjs-pino/README.md - UNPKG
Let's compare it to another one logger - `PinoLogger`, it has same _logging_ API as `pino` instance. 68.
Read more >
Multithreaded Logging with Pino by Matteo Collina - GitNation
In the upcoming version 7, we will solve this problem and increase throughput at the same time: we are introducing pino.transport() to start ......
Read more >
A Complete Guide to Pino Logging in Node.js - Better Stack
Learn how to start logging with Pino in Node.js and go from basics to best practices in no time.
Read more >
Node Logging Basics - The Ultimate Guide To Logging - Loggly
Error – a serious problem occurred while processing the current operation. ... Debug – used for debugging messages with extended information about ...
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