@sockethub/logger 1.0.0-alpha.11 → 1.0.0-alpha.12
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/dist/index.js +48 -4
- package/dist/index.js.map +3 -3
- package/package.json +2 -2
- package/src/index.test.ts +79 -0
- package/src/index.ts +39 -2
package/dist/index.js
CHANGED
|
@@ -4,15 +4,29 @@ var __getProtoOf = Object.getPrototypeOf;
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
7
12
|
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
8
20
|
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
9
21
|
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
10
22
|
for (let key of __getOwnPropNames(mod))
|
|
11
23
|
if (!__hasOwnProp.call(to, key))
|
|
12
24
|
__defProp(to, key, {
|
|
13
|
-
get: (
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
14
26
|
enumerable: true
|
|
15
27
|
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
16
30
|
return to;
|
|
17
31
|
};
|
|
18
32
|
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
@@ -9881,6 +9895,36 @@ var globalConfig = null;
|
|
|
9881
9895
|
var hasLoggedInit = false;
|
|
9882
9896
|
var loggerContext = "";
|
|
9883
9897
|
var loggerNamespaceStore = new WeakMap;
|
|
9898
|
+
function safeStringify(value) {
|
|
9899
|
+
try {
|
|
9900
|
+
const parents = [];
|
|
9901
|
+
return JSON.stringify(value, function(_key, innerValue) {
|
|
9902
|
+
if (innerValue instanceof Error) {
|
|
9903
|
+
return {
|
|
9904
|
+
name: innerValue.name,
|
|
9905
|
+
message: innerValue.message,
|
|
9906
|
+
stack: innerValue.stack
|
|
9907
|
+
};
|
|
9908
|
+
}
|
|
9909
|
+
if (typeof innerValue === "bigint") {
|
|
9910
|
+
return innerValue.toString();
|
|
9911
|
+
}
|
|
9912
|
+
if (typeof innerValue === "object" && innerValue !== null) {
|
|
9913
|
+
const parent = this;
|
|
9914
|
+
while (parents.length > 0 && parents[parents.length - 1] !== parent) {
|
|
9915
|
+
parents.pop();
|
|
9916
|
+
}
|
|
9917
|
+
if (parents.includes(innerValue)) {
|
|
9918
|
+
return "[Circular]";
|
|
9919
|
+
}
|
|
9920
|
+
parents.push(innerValue);
|
|
9921
|
+
}
|
|
9922
|
+
return innerValue;
|
|
9923
|
+
});
|
|
9924
|
+
} catch {
|
|
9925
|
+
return '"[Unserializable]"';
|
|
9926
|
+
}
|
|
9927
|
+
}
|
|
9884
9928
|
function initLogger(options) {
|
|
9885
9929
|
globalConfig = options;
|
|
9886
9930
|
if (!hasLoggedInit) {
|
|
@@ -9913,11 +9957,11 @@ function createLogger(namespace, options = {}) {
|
|
|
9913
9957
|
const isProduction = false;
|
|
9914
9958
|
const consoleFormat = isProduction ? import_winston.default.format.combine(import_winston.default.format.colorize(), import_winston.default.format.printf(({ level, message, namespace: namespace2, ...meta }) => {
|
|
9915
9959
|
const ns = namespace2 ? `${namespace2} ` : "";
|
|
9916
|
-
const metaStr = Object.keys(meta).length > 0 ? ` ${
|
|
9960
|
+
const metaStr = Object.keys(meta).length > 0 ? ` ${safeStringify(meta)}` : "";
|
|
9917
9961
|
return `${level}: ${ns}${message}${metaStr}`;
|
|
9918
9962
|
})) : import_winston.default.format.combine(import_winston.default.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), import_winston.default.format.colorize(), import_winston.default.format.printf(({ level, message, timestamp, namespace: namespace2, ...meta }) => {
|
|
9919
9963
|
const ns = namespace2 ? `${namespace2} ` : "";
|
|
9920
|
-
const metaStr = Object.keys(meta).length > 0 ? ` ${
|
|
9964
|
+
const metaStr = Object.keys(meta).length > 0 ? ` ${safeStringify(meta)}` : "";
|
|
9921
9965
|
return `${timestamp} ${level}: ${ns}${message}${metaStr}`;
|
|
9922
9966
|
}));
|
|
9923
9967
|
const transports = [
|
|
@@ -9960,4 +10004,4 @@ export {
|
|
|
9960
10004
|
createLogger
|
|
9961
10005
|
};
|
|
9962
10006
|
|
|
9963
|
-
//# debugId=
|
|
10007
|
+
//# debugId=E499E63CEE36E4A864756E2164756E21
|