Skip to content

Commit 5ed72fb

Browse files
authored
Merge pull request #118 from AthennaIO/develop
chore(json): better handle error logs
2 parents f526b02 + 43d524e commit 5ed72fb

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@athenna/logger",
3-
"version": "5.8.0",
3+
"version": "5.9.0",
44
"description": "The Athenna logging solution. Log in stdout, files and buckets.",
55
"license": "MIT",
66
"author": "João Lenon <lenon@athenna.io>",

src/formatters/JsonFormatter.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,32 @@ export class JsonFormatter extends Formatter {
2626
return JSON.stringify(base, this.getCircularReplacer())
2727
}
2828

29+
if (Is.Exception(message)) {
30+
return this.handleExceptionLog(base, message)
31+
}
32+
33+
if (Is.Error(message)) {
34+
return this.handleExceptionLog(base, message.toAthennaException())
35+
}
36+
2937
return JSON.stringify({ ...base, ...message }, this.getCircularReplacer())
3038
}
39+
40+
private handleExceptionLog(base: any, message: any) {
41+
return JSON.stringify(
42+
{
43+
...base,
44+
name: message.name,
45+
code: message.code,
46+
msg: message.message,
47+
help: message.help,
48+
status: message.status,
49+
cause: message.cause,
50+
details: message.details,
51+
metadata: message.otherInfos,
52+
stack: message.stack
53+
},
54+
this.getCircularReplacer()
55+
)
56+
}
3157
}

0 commit comments

Comments
 (0)