@trojs/logger 0.5.14 → 0.5.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@trojs/logger",
3
3
  "description": "Winston logger for TroJS",
4
- "version": "0.5.14",
4
+ "version": "0.5.16",
5
5
  "author": {
6
6
  "name": "Pieter Wigboldus",
7
7
  "url": "https://trojs.org/"
@@ -7,11 +7,16 @@ export default ({ winston, logger }) => {
7
7
  winston.format.errors({ stack: logger?.debug ?? false }),
8
8
  winston.format((info) => {
9
9
  if (!info.message) {
10
- info.message = info instanceof Error
11
- ? info.toString()
12
- : JSON.stringify(info)
10
+ if (info instanceof Error) {
11
+ info.message = info.message || info.toString()
12
+ } else {
13
+ const clone = { ...info }
14
+ delete clone.level
15
+ const keys = Object.keys(clone)
16
+ info.message = keys.length > 0 ? JSON.stringify(clone) : ''
17
+ }
13
18
  } else if (info.message instanceof Error) {
14
- info.message = info.message.toString()
19
+ info.message = info.message.message || info.message.toString()
15
20
  } else if (typeof info.message !== 'string') {
16
21
  info.message = JSON.stringify(info.message)
17
22
  }
@@ -34,8 +39,10 @@ export default ({ winston, logger }) => {
34
39
  const defaultFormatter = winston.format.combine(
35
40
  winston.format.errors({ stack: logger?.debug ?? false }),
36
41
  winston.format((info) => {
37
- if (!info.message && info instanceof Error) {
38
- info.message = info.toString()
42
+ if (info instanceof Error) {
43
+ info.message = info.message || info.toString()
44
+ } else if (!info.message) {
45
+ info.message = ''
39
46
  }
40
47
  return info
41
48
  })(),
@@ -44,6 +51,8 @@ export default ({ winston, logger }) => {
44
51
 
45
52
  return new winston.transports.Console({
46
53
  level: logger?.level || defaultLevel,
54
+ handleExceptions: true,
55
+ handleRejections: true,
47
56
  format:
48
57
  logger?.format === 'json'
49
58
  ? jsonFormatter