From 6ec5dc06d4595bdafc4c4cb74d53a797289e3c5b Mon Sep 17 00:00:00 2001 From: "Aman Jain (ECS/DEL)" Date: Wed, 21 Sep 2022 14:32:42 +0530 Subject: [PATCH 1/4] fix: updated the lib directory --- lib/index.d.ts | 4 +++- lib/index.js | 7 ++++--- package.json | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index 4a629e0..67e0f3a 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -1,2 +1,4 @@ import winston from "winston"; -export declare const logger: winston.Logger; +export declare const createLogger: ({ logLevel }: { + logLevel: string; +}) => winston.Logger; diff --git a/lib/index.js b/lib/index.js index 2a5a81f..aec562c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.logger = void 0; +exports.createLogger = void 0; const winston_1 = __importDefault(require("winston")); const { combine, errors, timestamp, splat, json } = winston_1.default.format; -exports.logger = winston_1.default.createLogger({ +const createLogger = ({ logLevel = "info" }) => winston_1.default.createLogger({ // default log level is "info" - level: "info", + level: logLevel, // combining multiple formats to get the desired output format: combine( // required to log errors thrown by the application; ignored otherwise @@ -31,3 +31,4 @@ exports.logger = winston_1.default.createLogger({ // generic metadata applied to all logs defaultMeta: { type: "application" } }); +exports.createLogger = createLogger; diff --git a/package.json b/package.json index b9b4faa..891a1f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "logger-safe-security", - "version": "1.1.0", + "version": "1.1.1", "description": "Custom logging framework used in SAFE", "main": "lib/index.js", "types": "lib", From 4b96c8e32d8f5e2d27f1e5662e95f8b2de458547 Mon Sep 17 00:00:00 2001 From: "Aman Jain (ECS/DEL)" Date: Wed, 21 Sep 2022 19:37:52 +0530 Subject: [PATCH 2/4] feat: added support to include service --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a873f1c..20ae757 100644 --- a/README.md +++ b/README.md @@ -37,13 +37,11 @@ const logger = createLogger({ logLevel: "info" }); logger.info("Hello world!"); ``` -Additionally, one can create child loggers inherited from the parent/package-default to pass specific metadata. -One such use case would be to add `service` metadata while importing it within the context of a service. For example: +Additionally, one can pass `service` metadata while importing it within the context of a service. For example: ```js const { createLogger } = require("logger-safe-security"); -const logger = createLogger(); -const serviceLogger = logger.child({ service: "sample" }); -serviceLogger.info("This log line will include service metadata"); +const logger = createLogger({ service: "sample" }); +logger.info("This log line will include service metadata"); ``` ## Definition From 4251283bdfe2942b314a96bb9be8d0675489b3ef Mon Sep 17 00:00:00 2001 From: "Aman Jain (ECS/DEL)" Date: Thu, 22 Sep 2022 19:40:07 +0530 Subject: [PATCH 3/4] fix: updated logger not to exit after logging an uncaughtException --- src/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/index.ts b/src/index.ts index eab2bc6..a3ea17e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,6 +45,9 @@ export const createLogger = ( }) ], + // do not exit the process after logging an uncaughtException + exitOnError: false, + // generic metadata applied to all logs defaultMeta: { type: "application", ...(service && { service }) } }); From 9209c35715acdd43e8307b1d818a5ccfa180f887 Mon Sep 17 00:00:00 2001 From: "Aman Jain (ECS/DEL)" Date: Thu, 22 Sep 2022 19:45:55 +0530 Subject: [PATCH 4/4] fix: updated logger not to exit after logging an uncaughtException --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8e78116..2f96747 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "logger-safe-security", - "version": "1.1.3", + "version": "1.1.4", "description": "Custom logging framework used in SAFE", "main": "lib/index.js", "types": "lib",