@unchainedshop/logger 4.8.20 → 4.8.22
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/lib/createLogger.js +2 -8
- package/lib/logger-index.d.ts +1 -0
- package/lib/logger-index.js +1 -0
- package/lib/safe-stringify.d.ts +2 -0
- package/lib/safe-stringify.js +19 -0
- package/package.json +1 -4
package/lib/createLogger.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { inspect } from 'node:util';
|
|
2
|
-
import {
|
|
2
|
+
import { safeStringify } from "./safe-stringify.js";
|
|
3
3
|
import { LogLevel } from "./logger.types.js";
|
|
4
4
|
const regexCache = new Map();
|
|
5
5
|
const debugPatternCache = new Map();
|
|
@@ -87,12 +87,6 @@ const formatTimestamp = () => {
|
|
|
87
87
|
const seconds = now.getSeconds().toString().padStart(2, '0');
|
|
88
88
|
return `${hours}:${minutes}:${seconds}`;
|
|
89
89
|
};
|
|
90
|
-
const bigintReplacer = (_key, value) => {
|
|
91
|
-
if (typeof value === 'bigint') {
|
|
92
|
-
return value.toString();
|
|
93
|
-
}
|
|
94
|
-
return value;
|
|
95
|
-
};
|
|
96
90
|
export const resetLoggerInitialization = () => {
|
|
97
91
|
regexCache.clear();
|
|
98
92
|
debugPatternCache.clear();
|
|
@@ -130,7 +124,7 @@ export const createLogger = (moduleName) => {
|
|
|
130
124
|
logObject[key] = args[0][key];
|
|
131
125
|
}
|
|
132
126
|
}
|
|
133
|
-
console.log(
|
|
127
|
+
console.log(safeStringify(logObject));
|
|
134
128
|
}
|
|
135
129
|
else {
|
|
136
130
|
const timestamp = formatTimestamp();
|
package/lib/logger-index.d.ts
CHANGED
package/lib/logger-index.js
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function safeStringify(value, replacer, space) {
|
|
2
|
+
const ancestors = [];
|
|
3
|
+
return JSON.stringify(value, function (key, val) {
|
|
4
|
+
const replaced = replacer ? replacer.call(this, key, val) : val;
|
|
5
|
+
if (typeof replaced === 'bigint')
|
|
6
|
+
return replaced.toString();
|
|
7
|
+
if (typeof replaced !== 'object' || replaced === null)
|
|
8
|
+
return replaced;
|
|
9
|
+
if (replaced instanceof BigInt)
|
|
10
|
+
return String(replaced);
|
|
11
|
+
while (ancestors.length > 0 && ancestors[ancestors.length - 1] !== this)
|
|
12
|
+
ancestors.pop();
|
|
13
|
+
if (ancestors.includes(replaced))
|
|
14
|
+
return '[Circular]';
|
|
15
|
+
ancestors.push(replaced);
|
|
16
|
+
return replaced;
|
|
17
|
+
}, space);
|
|
18
|
+
}
|
|
19
|
+
export default safeStringify;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/logger",
|
|
3
3
|
"description": "High-performance logging package for the Unchained Engine",
|
|
4
|
-
"version": "4.8.
|
|
4
|
+
"version": "4.8.22",
|
|
5
5
|
"main": "lib/logger-index.js",
|
|
6
6
|
"types": "lib/logger-index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -36,9 +36,6 @@
|
|
|
36
36
|
"url": "https://github.com/unchainedshop/unchained/issues"
|
|
37
37
|
},
|
|
38
38
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
39
|
-
"dependencies": {
|
|
40
|
-
"safe-stable-stringify": "^2.5.0"
|
|
41
|
-
},
|
|
42
39
|
"devDependencies": {
|
|
43
40
|
"@types/node": "^26.2.0",
|
|
44
41
|
"typescript": "^5.8.3"
|