From f8984dac607c27a23f698e2279e5a18c972b8394 Mon Sep 17 00:00:00 2001 From: Egor Kartashov Date: Fri, 19 Jan 2024 21:34:21 +0600 Subject: [PATCH] fix: logger json --- .../src/infrastructure/configs/logger.config.ts | 3 +++ examples/replace-nest-logger-bootstrap/src/main.ts | 12 ++++++------ .../winston/transports/console/console.transport.ts | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/replace-nest-logger-bootstrap/src/infrastructure/configs/logger.config.ts b/examples/replace-nest-logger-bootstrap/src/infrastructure/configs/logger.config.ts index 0ae790d..dc8c6b1 100644 --- a/examples/replace-nest-logger-bootstrap/src/infrastructure/configs/logger.config.ts +++ b/examples/replace-nest-logger-bootstrap/src/infrastructure/configs/logger.config.ts @@ -12,6 +12,9 @@ export class LoggerConfig implements ILoggerConfigFactory { constructor() { this._opts = { hideTrace: false, + console: { + format: 'json', + }, meta: { organization: 'NestJS ProLogger', context: 'service', diff --git a/examples/replace-nest-logger-bootstrap/src/main.ts b/examples/replace-nest-logger-bootstrap/src/main.ts index 1b2f908..6911a82 100644 --- a/examples/replace-nest-logger-bootstrap/src/main.ts +++ b/examples/replace-nest-logger-bootstrap/src/main.ts @@ -1,15 +1,17 @@ import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import { LogLevels } from '@wildegor/nestjs-prologger/modules/infrastructure/interfaces/logger.interfaces'; -import { LoggerAdapter } from '@wildegor/nestjs-prologger/modules/modules/logger/logger.adapter'; -import { NestExpressApplication } from '@nestjs/platform-express'; +// import { LoggerAdapter } from '@wildegor/nestjs-prologger/modules/modules/logger/logger.adapter'; +// import { NestExpressApplication } from '@nestjs/platform-express'; +import { LoggerService } from '@wildegor/nestjs-prologger/modules/modules/logger/logger.service'; +import { LoggerConstants } from '@wildegor/nestjs-prologger/modules/modules/logger/logger.constants'; async function bootstrap() { - const app = await NestFactory.create(AppModule, { + const app = await NestFactory.create(AppModule, { bufferLogs: true, }); - const logger = await app.resolve(LoggerAdapter); + const logger = await app.resolve(LoggerConstants.logger); logger.setLogLevels([ LogLevels.Debug, LogLevels.Log, @@ -20,8 +22,6 @@ async function bootstrap() { app.useLogger(logger); - logger.error('Error message'); - await app.listen(3001); } bootstrap(); diff --git a/src/infrastructure/adapters/winston/transports/console/console.transport.ts b/src/infrastructure/adapters/winston/transports/console/console.transport.ts index 0bae2eb..9ab31a3 100644 --- a/src/infrastructure/adapters/winston/transports/console/console.transport.ts +++ b/src/infrastructure/adapters/winston/transports/console/console.transport.ts @@ -11,7 +11,7 @@ export class ConsoleTransport { if (opts?.format && 'json' === opts.format) { return new winston.transports.Console({ format: winston.format.json({ - deterministic: true, + // deterministic: true, }), }); }