From acd9550725294fbafbdadda891d26011a8091df7 Mon Sep 17 00:00:00 2001 From: demmorou Date: Tue, 30 Apr 2024 07:48:38 -0300 Subject: [PATCH] feat: add isDev prop options on logger instance --- packages/logger/package.json | 2 +- packages/logger/src/implementations/logger.ts | 8 ++++++-- packages/logger/src/interfaces/logger.interfaces.ts | 3 ++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/logger/package.json b/packages/logger/package.json index 7ac885f..b092181 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -1,6 +1,6 @@ { "name": "@demmorou/logger", - "version": "1.0.6", + "version": "1.0.7", "author": "Deusimar (@demmorou)", "description": "Custom logger implementation with winston", "main": "dist/index.js", diff --git a/packages/logger/src/implementations/logger.ts b/packages/logger/src/implementations/logger.ts index 6adbe08..ee7f3d8 100644 --- a/packages/logger/src/implementations/logger.ts +++ b/packages/logger/src/implementations/logger.ts @@ -19,7 +19,11 @@ export class Logger { this.logger = winston.createLogger({ level: "debug", - defaultMeta: { ...this.options }, + defaultMeta: { + env: this.options.env, + app_name: this.options.app_name, + version: this.options.version, + }, format: winston.format.combine( winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), winston.format.metadata({ @@ -28,7 +32,7 @@ export class Logger { winston.format.json() ), transports: [ - this.options.env === "develop" + this.options.isDev ? new winston.transports.Console({ format: winston.format.combine( winston.format.colorize({ all: true }), diff --git a/packages/logger/src/interfaces/logger.interfaces.ts b/packages/logger/src/interfaces/logger.interfaces.ts index e51ee9a..d502fbe 100644 --- a/packages/logger/src/interfaces/logger.interfaces.ts +++ b/packages/logger/src/interfaces/logger.interfaces.ts @@ -1,5 +1,6 @@ export type LoggerOptions = { app_name: string; version: string; - env?: string; + isDev: boolean; + env: string; };