Skip to content

Commit

Permalink
Merge pull request #47 from hiro5id/no-new-line-for-logs-except-stack…
Browse files Browse the repository at this point in the history
…-traces

add ability to disable new lines only for regural logs but not for stack traces
  • Loading branch information
hiro5id authored Dec 26, 2022
2 parents 4fe003c + ce94e8e commit a2d3b48
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 a2d3b48

Please sign in to comment.