@athenna/logger 5.4.0 → 5.6.0
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
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
+
import { debug } from '#src/debug';
|
|
9
10
|
import { File } from '@athenna/common';
|
|
10
11
|
import { Driver } from '#src/drivers/Driver';
|
|
11
|
-
import { debug } from '#src/debug';
|
|
12
12
|
export class FileDriver extends Driver {
|
|
13
13
|
async transport(level, message) {
|
|
14
14
|
if (!this.couldBeTransported(level)) {
|
|
@@ -6,16 +6,20 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
+
import { debug } from '#src/debug';
|
|
9
10
|
import { Json } from '@athenna/common';
|
|
10
11
|
import { Driver } from '#src/drivers/Driver';
|
|
11
12
|
import { DriverFactory } from '#src/factories/DriverFactory';
|
|
12
|
-
import { debug } from '#src/debug';
|
|
13
13
|
export class StackDriver extends Driver {
|
|
14
14
|
transport(level, message) {
|
|
15
15
|
const configs = Json.copy(this.configs);
|
|
16
16
|
delete configs.driver;
|
|
17
17
|
delete configs.channels;
|
|
18
18
|
debug('[%s] Transporting logs in channels: %s.', StackDriver.name, this.driverConfig.channels.join(', '));
|
|
19
|
-
|
|
19
|
+
const promises = this.driverConfig.channels.map(channel => {
|
|
20
|
+
const channelConfig = configs?.[channel];
|
|
21
|
+
return DriverFactory.fabricate(channel, channelConfig).transport(level, message);
|
|
22
|
+
});
|
|
23
|
+
return Promise.all(promises);
|
|
20
24
|
}
|
|
21
25
|
}
|
|
@@ -39,6 +39,11 @@ export declare abstract class Formatter {
|
|
|
39
39
|
* Create the timestamp for formatter.
|
|
40
40
|
*/
|
|
41
41
|
timestamp(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Get the circular replacer function to be used in
|
|
44
|
+
* JSON.stringify().
|
|
45
|
+
*/
|
|
46
|
+
getCircularReplacer(): (key: any, value: any) => any;
|
|
42
47
|
/**
|
|
43
48
|
* Transform the message to string.
|
|
44
49
|
*/
|
|
@@ -61,6 +61,26 @@ export class Formatter {
|
|
|
61
61
|
};
|
|
62
62
|
return new Date(Date.now()).toLocaleString(undefined, localeStringOptions);
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Get the circular replacer function to be used in
|
|
66
|
+
* JSON.stringify().
|
|
67
|
+
*/
|
|
68
|
+
getCircularReplacer() {
|
|
69
|
+
const ancestors = [];
|
|
70
|
+
return function (key, value) {
|
|
71
|
+
if (!Is.Object(value) || value === null) {
|
|
72
|
+
return value;
|
|
73
|
+
}
|
|
74
|
+
while (ancestors.length > 0 && ancestors.at(-1) !== this) {
|
|
75
|
+
ancestors.pop();
|
|
76
|
+
}
|
|
77
|
+
if (ancestors.includes(value)) {
|
|
78
|
+
return '[Circular]';
|
|
79
|
+
}
|
|
80
|
+
ancestors.push(value);
|
|
81
|
+
return value;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
64
84
|
/**
|
|
65
85
|
* Transform the message to string.
|
|
66
86
|
*/
|
|
@@ -69,7 +89,7 @@ export class Formatter {
|
|
|
69
89
|
return message;
|
|
70
90
|
}
|
|
71
91
|
if (Is.Object(message)) {
|
|
72
|
-
message = JSON.stringify(message);
|
|
92
|
+
message = JSON.stringify(message, this.getCircularReplacer());
|
|
73
93
|
}
|
|
74
94
|
return `${message}`;
|
|
75
95
|
}
|
|
@@ -19,8 +19,8 @@ export class JsonFormatter extends Formatter {
|
|
|
19
19
|
};
|
|
20
20
|
if (Is.String(message)) {
|
|
21
21
|
base.msg = message;
|
|
22
|
-
return JSON.stringify(base);
|
|
22
|
+
return JSON.stringify(base, this.getCircularReplacer());
|
|
23
23
|
}
|
|
24
|
-
return JSON.stringify({ ...base, ...message });
|
|
24
|
+
return JSON.stringify({ ...base, ...message }, this.getCircularReplacer());
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -44,6 +44,6 @@ export class RequestFormatter extends Formatter {
|
|
|
44
44
|
body: ctx.response.body,
|
|
45
45
|
headers: ctx.response.headers
|
|
46
46
|
};
|
|
47
|
-
return JSON.stringify({ request, response, metadata });
|
|
47
|
+
return JSON.stringify({ request, response, metadata }, this.getCircularReplacer());
|
|
48
48
|
}
|
|
49
49
|
}
|