'Extend NestJS Logger (old version) - where can i set LogLevels
I create a extended logger based like the answer of Ian: Issue with using Azure Applications Insights sdk with NestJS logger
NestJS old version:
export class MyLogger extends Logger {
Normally you can set the log-level for the nestjs logger:
const app = await NestFactory.create(AppModule, {
logger: ['error', 'warn'],
});
But how can i set the LogLevels if i extend the Logger.
const app = await NestFactory.create(AppModule);
const logger = await app.resolve(MyLogger);
logger.setClient(appInsights.defaultClient);
app.useLogger(logger);
Solution 1:[1]
- If your application uses a custom logger class that extends the built-in
Logger, you should update it to extend theConsoleLoggernow.
Before:
export class MyLogger extends Logger {}
Now:
export class MyLogger extends ConsoleLogger {}
extend the built-in ConsoleLogger class
export class MyLogger extends ConsoleLogger
const app = await NestFactory.create(ApplicationModule, {
bufferLogs: true,
});
app.useLogger(app.get(MyLogger));
await app.listen(3000);
Please refer Extend built-in logger , this for more information
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | HarshithaVeeramalla-MT |
