[QUESTION] Extend PinoLogger class
See original GitHub issueHi 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:
- Created 3 years ago
- Comments:16 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
until PR gets merged, @iamolegga, or @dguyonvarch what is the work around for adding a wrapper around the Logger?
@dguyonvarch feel free to open pr for this