Comments (8)
@TroyMorvant No, winston is used. All steps are taken from readme.
I think secret is here:
const app = await NestFactory.create(AppModule, {
logger: WinstonModule.createLogger({
// options (same as WinstonModule.forRoot() options)
})
And then import from @nestjs/common
should be used
from nest-winston.
Description
I've picked "Replacing the Nest logger (also for bootstrapping)" to setup logger.
In the end of section there are 2 requirements:
- Add
Logger
toAppModule
providers.- Inject in class constructor:
import { Controller, Logger } from '@nestjs/common'; @Controller('cats') export class CatsController { constructor(private readonly logger: Logger) {} }But as a result I am getting next error:
Error: Nest can't resolve dependencies of the CatsController
After some investigation I found another way to use logger in class in official documentation here.
import { Logger, Injectable } from '@nestjs/common'; @Injectable() class MyService { private readonly logger = new Logger(MyService.name); doSomething() { this.logger.log('Doing something...'); } }And now everything is works. No need to add into providers list. So yeah.. Is it ok? Should documentation be updated?
Wouldn't this just be using the built in nest logger and not the custom logger?
from nest-winston.
Same here.
private readonly logger = new Logger(MyService.name);
Seems to work instead of trying to put it in the constructor.
from nest-winston.
Solve it in another way
app.module.ts
@global() // important
@module({
providers: [Logger],
exports: [Logger], // important
})
export class AppModule {}
from nest-winston.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.
from nest-winston.
This issue was closed because it has been stalled for 7 days with no activity.
from nest-winston.
I definitely think the documentation should be updated. Since most people will be migrating from the default nest way of using the logger which is exactly the same the @inferusvv solution it is much less effort.
from nest-winston.
waste a week to solve this problem
from nest-winston.
Related Issues (20)
- Nest can't resolve dependencies HOT 8
- Default context per service (configurable injection scope) HOT 3
- Passing winston logger instance to forRoot doesn't work HOT 2
- [Bug]: Creating multiple winston modules using child winston loggers use the last created winston module when using the nestjs Logger constructor HOT 2
- Adding "level" argument to log method HOT 2
- NestLike ConsoleFormat always contains stringifiedMeta and essentially logs message twice HOT 7
- LoggerService interface changed with Nest v8 HOT 2
- Is there a way to create a child logger? HOT 3
- How can I pass json attributes into the logger? HOT 3
- Support for @nestjs/common 10.0.0 in Peer Dependencies HOT 2
- [Feature]: Support string-interpolation HOT 1
- [Question]: How to get trace_id ? HOT 4
- [Feature]: add fatal level HOT 6
- [Question]: How can I access a request scope injectable when replacing the Nest logger (including boostrap) ? HOT 2
- [Question]: Winston creates file but does not save to it
- [Question]: processing optional arguments is not consistent with Nest HOT 4
- [Bug]: Redundant Stack Information in Error Logs HOT 2
- [Bug]: Code for v1.9.5 of Nest Winston not in NPM HOT 4
- [Bug]: Providing Logger from @nestjs/common as a provider in AppModule doesn't make it available globally to other modules/services. HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nest-winston.