From ce94e8e8ba95ff3b892482c709651c9e0822c69b Mon Sep 17 00:00:00 2001 From: Roberto Sebestyen Date: Mon, 26 Dec 2022 05:11:26 -0500 Subject: [PATCH] add ability to disable new lines only for regural logs but not for stack traces #40 --- README.md | 2 ++ src/logger.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 58ff4a0..0da97d3 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,8 @@ To suppress some bits of the log to make it less noisy you can set these environ * Omits `_loggerDebug` in log * CONSOLE_LOG_JSON_NO_NEW_LINE_CHARACTERS="true" * Omits `\n` new line characters in the log string. -- the presence of these can help format the log for readability for some log analyzers. But it can cause problems for others. You can turn them off with this. +* CONSOLE_LOG_JSON_NO_NEW_LINE_CHARACTERS_EXCEPT_STACK + * Omits `\n` new line character only for the log string, but retains it for stack traces ## Examples diff --git a/src/logger.ts b/src/logger.ts index 0535089..6dac44c 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -106,7 +106,7 @@ declare global { export function FormatErrorObject(object: any) { let returnData: any = object; - const { CONSOLE_LOG_JSON_NO_NEW_LINE_CHARACTERS } = process.env; + const { CONSOLE_LOG_JSON_NO_NEW_LINE_CHARACTERS, CONSOLE_LOG_JSON_NO_NEW_LINE_CHARACTERS_EXCEPT_STACK } = process.env; // Flatten message if it is an object if (typeof object.message === 'object') { @@ -209,7 +209,7 @@ export function FormatErrorObject(object: any) { // add new line at the end for better local readability let endOfLogCharacter = '\n'; - if (CONSOLE_LOG_JSON_NO_NEW_LINE_CHARACTERS) { + if (CONSOLE_LOG_JSON_NO_NEW_LINE_CHARACTERS || CONSOLE_LOG_JSON_NO_NEW_LINE_CHARACTERS_EXCEPT_STACK) { endOfLogCharacter = ''; } return `${colorStripped}${endOfLogCharacter}`;