restructure directories

* set log level based on env
This commit is contained in:
Philipinho
2024-06-09 15:57:52 +01:00
parent 2e61fb7c11
commit d4eefa48a8
49 changed files with 124 additions and 82 deletions
@@ -0,0 +1,58 @@
import { ConsoleLogger } from '@nestjs/common';
export class InternalLogFilter extends ConsoleLogger {
static contextsToIgnore = [
'InstanceLoader',
'RoutesResolver',
'RouterExplorer',
'WebSocketsController',
];
private allowedLogLevels: string[];
constructor() {
super();
this.allowedLogLevels =
process.env.NODE_ENV === 'production'
? ['log', 'error', 'fatal']
: ['log', 'debug', 'verbose', 'warn', 'error', 'fatal'];
}
private isLogLevelAllowed(level: string): boolean {
return this.allowedLogLevels.includes(level);
}
log(_: any, context?: string): void {
if (
this.isLogLevelAllowed('log') &&
(process.env.NODE_ENV !== 'production' ||
!InternalLogFilter.contextsToIgnore.includes(context))
) {
super.log.apply(this, arguments);
}
}
warn(_: any, context?: string): void {
if (this.isLogLevelAllowed('warn')) {
super.warn.apply(this, arguments);
}
}
error(_: any, stack?: string, context?: string): void {
if (this.isLogLevelAllowed('error')) {
super.error.apply(this, arguments);
}
}
debug(_: any, context?: string): void {
if (this.isLogLevelAllowed('debug')) {
super.debug.apply(this, arguments);
}
}
verbose(_: any, context?: string): void {
if (this.isLogLevelAllowed('verbose')) {
super.verbose.apply(this, arguments);
}
}
}