Skip to content

Commit

Permalink
add ability to disable new lines only for regural logs but not for st…
Browse files Browse the repository at this point in the history
…ack traces #40
  • Loading branch information
hiro5id committed Dec 26, 2022
1 parent 4fe003c commit ce94e8e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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}`;
Expand Down

0 comments on commit ce94e8e

Please sign in to comment.