owen1002 / nestjs-winston-logger Goto Github PK
View Code? Open in Web Editor NEWA logger integrating winston and wrapped by nestjs
Home Page: https://github.com/owen1002/nestjs-winston-logger
License: MIT License
A logger integrating winston and wrapped by nestjs
Home Page: https://github.com/owen1002/nestjs-winston-logger
License: MIT License
import { InjectLogger, NestjsWinstonLoggerService } from 'nestjs-winston-logger';
export class DemoService {
constructor(@InjectLogger(DemoService.name) private logger: NestjsWinstonLoggerService) {}
}
In my imagination, setContext inside at decorator may be more convenient.
did you plan to upgrade this module to be compatible with nestjs v8?
Before I start, I just wanted to say great library. I learned a bit more about using nest from looking at your code.
Anyway, from what I can tell, we can create several different loggers using @InjectLogger("someContext")
but they all share the same configuration from single global logger. What I need to be able to do is create different loggers that write different things to different files.
Specifically, I would like a separate request log for the API requests, authentication log, error log, and debug log. The error log and debug log can share the same config since the only difference is log level but the authentication log and request log are entirely different things and I don't want information from there going into a debug log.
I assumed that I could do something like @InjectLogger(AUTH_LOG) and @InjectLogger(REQ_LOG) to create the logs, but don't quite see how to configure them.
I found another issue as well. In addition to having different loggers, I want to have a request id across all logs. There is a great method to do this for a global log but if I want to do it for specific logs, my first approach is:
const requestLogger = new NestjsWinstonLoggerService({ format:format.simple(), transports: [ new transports.File({ filename: "request.log", format: format.printf(log => log.message.trim()) }), ], }); let authLog = app.get(getLoggerToken(AUTH_LOG)); app.use(appendIdToRequest); app.use(appendRequestIdToLogger(requestLogger)); app.use(appendRequestIdToLogger(authLog)); configMorgan.appendMorganToken("reqId", TOKEN_TYPE.Request, "reqId"); app.use(morganRequestLogger(requestLogger)); app.use(morganResponseLogger(requestLogger));The issue here is that I'm now exposing some of the internals through getLoggerToken. I think there should be a better way to do this but I haven't thought much about it yet.
This issue may adopt to use Nestjs middleware rather than global middleware. We can open another issue for further discussion. For you reference - https://docs.nestjs.com/middleware
Originally posted by @Marcotsept in #8 (comment)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.