You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I set the allowed log levels by using the ConfigService?
I tried to do it through main.ts but the logLevels are set during the app creation call which is also required to get the ConfigService.
constapp=awaitNestFactory.create(AppModule.register(),{logger: configService.get('LOG_LEVELS')}// <-- at this point I still can't do: const configService = app.get(ConfigService););
Is is possible to create the app object with the logLevels set to default and then override it? Something like this:
Also tried a different avenue but the solution is not ideal. I tried first to set the logLevels in the constructor of MyLogger but the class member logLevels is private to Logger so I can't override it. The same seems to be the case for the method isLogLevelEnabled(level).
The only option I found so far is to check the logLevels allowed inside the actual logging methods: log, warn, error, etc...
@Injectable()exportclassMyLoggerextendsLogger{constructor(privateconfigService: ConfigService){super();MyLogger.logLevels=configService.get('LOG_LEVELS')// <-- can't set because it's private to Logger}isLogLevelEnabled(level){}// <-- can't override because it's private to Loggerlog(message: any,context? string): void{constlogLevels=this.configService.get('LOG_LEVELS');// check if this method has the right level to log the message depending on logLevels before proceedingsuper.log(message,context);}}
Is there a better way to do this?
The text was updated successfully, but these errors were encountered:
How can I set the allowed log levels by using the ConfigService?
I tried to do it through main.ts but the logLevels are set during the
app
creation call which is also required toget
the ConfigService.Is is possible to create the
app
object with the logLevels set to default and then override it? Something like this:Also tried a different avenue but the solution is not ideal. I tried first to set the logLevels in the constructor of MyLogger but the class member logLevels is private to Logger so I can't override it. The same seems to be the case for the method
isLogLevelEnabled(level)
.The only option I found so far is to check the logLevels allowed inside the actual logging methods: log, warn, error, etc...
Is there a better way to do this?
The text was updated successfully, but these errors were encountered: