fix: logger ctx

This commit is contained in:
Mohamed Marrouchi 2025-01-27 10:46:14 +01:00
parent ae4bfcfe89
commit f52c82e82a
4 changed files with 16 additions and 9 deletions

View File

@ -108,7 +108,7 @@ describe('AttachmentController', () => {
helperService = module.get<HelperService>(HelperService);
settingService = module.get<SettingService>(SettingService);
loggerService = module.get<LoggerService>(LoggerService);
loggerService = await module.resolve<LoggerService>(LoggerService);
helperService.register(
new LocalStorageHelper(settingService, helperService, loggerService),

View File

@ -1,11 +1,17 @@
/*
* Copyright © 2024 Hexastack. All rights reserved.
* Copyright © 2025 Hexastack. All rights reserved.
*
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
*/
import { ConsoleLogger } from '@nestjs/common';
import { ConsoleLogger, Inject, Injectable, Scope } from '@nestjs/common';
import { INQUIRER } from '@nestjs/core';
export class LoggerService extends ConsoleLogger {}
@Injectable({ scope: Scope.TRANSIENT })
export class LoggerService extends ConsoleLogger {
constructor(@Inject(INQUIRER) private parentClass: object) {
super(parentClass.constructor.name);
}
}

View File

@ -101,10 +101,11 @@ async function bootstrap() {
app.useWebSocketAdapter(redisIoAdapter);
}
process.on('uncaughtException', (error) => {
if (error.stack?.toLowerCase().includes('smtp'))
app.get(LoggerService).error('SMTP error', error.stack);
else throw error;
process.on('uncaughtException', async (error) => {
if (error.stack?.toLowerCase().includes('smtp')) {
const logger = await app.resolve(LoggerService);
logger.error('SMTP error', error.stack);
} else throw error;
});
if (!isProduction) {

View File

@ -37,7 +37,7 @@ import { UserSeeder } from './user/seeds/user.seed';
import { userModels } from './user/seeds/user.seed-model';
export async function seedDatabase(app: INestApplicationContext) {
const logger = app.get(LoggerService);
const logger = await app.resolve(LoggerService);
const modelSeeder = app.get(ModelSeeder);
const categorySeeder = app.get(CategorySeeder);
const contextVarSeeder = app.get(ContextVarSeeder);