Skip to content

Commit

Permalink
Correct format function type name in default stringify func
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandro-bottamedi committed Jan 25, 2024
1 parent 9cd22e5 commit 592e139
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ let stringifyFunc = (msg: any): string => {
if (typeof msg === "string") {
stringMsg = msg + " ";
} else if (typeof msg === "function") {
stringMsg = "[function] ";
stringMsg = "[function " + msg.name + "()] ";
} else if (msg && msg.stack && msg.message) {
stringMsg = msg.message + " ";
} else {
try {
stringMsg = "\n" + JSON.stringify(msg, Object.getOwnPropertyNames(msg), 2) + "\n";
stringMsg =
"\n" + JSON.stringify(msg, Object.getOwnPropertyNames(msg), 2) + "\n";
} catch (error) {
stringMsg += "Undefined Message";
}
Expand Down
9 changes: 5 additions & 4 deletions test/consoleTransport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ test("The log function should print string, beutified objects and functions in c
outputExp = `{\n \"message\": \"message\"\n}`;
expect(outputData).toBe(outputExp);
outputData = "";
log.debug(() => {
return true;
});
outputExp = `[function]`;
function testFunc() {
return "test";
}
log.debug(testFunc);
outputExp = `[function testFunc()]`;
expect(outputData).toBe(outputExp);
});

Expand Down

0 comments on commit 592e139

Please sign in to comment.