@dxos/log 0.8.4-main.67995b8 → 0.8.4-main.69d29f4
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/lib/browser/chunk-GPOFUMLO.mjs +133 -0
- package/dist/lib/browser/chunk-GPOFUMLO.mjs.map +7 -0
- package/dist/lib/browser/chunk-IEP6GGEX.mjs +23 -0
- package/dist/lib/browser/chunk-IEP6GGEX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +136 -177
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/platform/browser/index.mjs +26 -0
- package/dist/lib/browser/platform/browser/index.mjs.map +7 -0
- package/dist/lib/browser/platform/node/index.mjs +21 -0
- package/dist/lib/browser/platform/node/index.mjs.map +7 -0
- package/dist/lib/browser/processors/console-processor.mjs +107 -0
- package/dist/lib/browser/processors/console-processor.mjs.map +7 -0
- package/dist/lib/browser/processors/console-stub.mjs +9 -0
- package/dist/lib/browser/processors/console-stub.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
- package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-QPYJZ4SO.mjs +135 -0
- package/dist/lib/node-esm/chunk-QPYJZ4SO.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +133 -259
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/platform/browser/index.mjs +27 -0
- package/dist/lib/node-esm/platform/browser/index.mjs.map +7 -0
- package/dist/lib/node-esm/platform/node/index.mjs +22 -0
- package/dist/lib/node-esm/platform/node/index.mjs.map +7 -0
- package/dist/lib/node-esm/processors/console-processor.mjs +108 -0
- package/dist/lib/node-esm/processors/console-processor.mjs.map +7 -0
- package/dist/lib/node-esm/processors/console-stub.mjs +10 -0
- package/dist/lib/node-esm/processors/console-stub.mjs.map +7 -0
- package/dist/types/src/config.d.ts +2 -3
- package/dist/types/src/config.d.ts.map +1 -1
- package/dist/types/src/context.d.ts.map +1 -1
- package/dist/types/src/decorators.d.ts +1 -1
- package/dist/types/src/decorators.d.ts.map +1 -1
- package/dist/types/src/log.d.ts +12 -18
- package/dist/types/src/log.d.ts.map +1 -1
- package/dist/types/src/options.d.ts +1 -6
- package/dist/types/src/options.d.ts.map +1 -1
- package/dist/types/src/platform/index.d.ts +1 -1
- package/dist/types/src/platform/index.d.ts.map +1 -1
- package/dist/types/src/platform/node/index.d.ts.map +1 -1
- package/dist/types/src/processors/browser-processor.d.ts.map +1 -1
- package/dist/types/src/processors/console-processor.d.ts.map +1 -1
- package/dist/types/src/processors/file-processor.d.ts.map +1 -1
- package/dist/types/src/processors/index.d.ts +3 -3
- package/dist/types/src/processors/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -11
- package/src/config.ts +3 -2
- package/src/context.ts +36 -5
- package/src/decorators.ts +5 -4
- package/src/experimental/classes.test.ts +2 -1
- package/src/log.test.ts +49 -18
- package/src/log.ts +101 -57
- package/src/options.ts +27 -11
- package/src/platform/index.ts +1 -1
- package/src/platform/node/index.ts +2 -1
- package/src/processors/browser-processor.ts +3 -1
- package/src/processors/console-processor.ts +9 -5
- package/src/processors/file-processor.ts +4 -1
- package/src/processors/index.ts +3 -3
- package/src/scope.ts +1 -1
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/config.ts
|
|
4
|
+
var LogLevel = /* @__PURE__ */ (function(LogLevel2) {
|
|
5
|
+
LogLevel2[LogLevel2["TRACE"] = 5] = "TRACE";
|
|
6
|
+
LogLevel2[LogLevel2["DEBUG"] = 10] = "DEBUG";
|
|
7
|
+
LogLevel2[LogLevel2["VERBOSE"] = 11] = "VERBOSE";
|
|
8
|
+
LogLevel2[LogLevel2["INFO"] = 12] = "INFO";
|
|
9
|
+
LogLevel2[LogLevel2["WARN"] = 13] = "WARN";
|
|
10
|
+
LogLevel2[LogLevel2["ERROR"] = 14] = "ERROR";
|
|
11
|
+
return LogLevel2;
|
|
12
|
+
})({});
|
|
13
|
+
var levels = {
|
|
14
|
+
"*": 5,
|
|
15
|
+
trace: 5,
|
|
16
|
+
debug: 10,
|
|
17
|
+
verbose: 11,
|
|
18
|
+
info: 12,
|
|
19
|
+
warn: 13,
|
|
20
|
+
error: 14
|
|
21
|
+
};
|
|
22
|
+
var shortLevelName = {
|
|
23
|
+
[5]: "T",
|
|
24
|
+
[10]: "D",
|
|
25
|
+
[11]: "V",
|
|
26
|
+
[12]: "I",
|
|
27
|
+
[13]: "W",
|
|
28
|
+
[14]: "E"
|
|
29
|
+
};
|
|
30
|
+
var LogProcessorType = /* @__PURE__ */ (function(LogProcessorType2) {
|
|
31
|
+
LogProcessorType2["CONSOLE"] = "console";
|
|
32
|
+
LogProcessorType2["BROWSER"] = "browser";
|
|
33
|
+
LogProcessorType2["DEBUG"] = "debug";
|
|
34
|
+
return LogProcessorType2;
|
|
35
|
+
})({});
|
|
36
|
+
|
|
37
|
+
// src/scope.ts
|
|
38
|
+
var logInfoProperties = Symbol("logInfoProperties");
|
|
39
|
+
var logInfo = (target, propertyKey, descriptor) => {
|
|
40
|
+
(target[logInfoProperties] ??= []).push(propertyKey);
|
|
41
|
+
};
|
|
42
|
+
var gatherLogInfoFromScope = (scope) => {
|
|
43
|
+
if (!scope) {
|
|
44
|
+
return {};
|
|
45
|
+
}
|
|
46
|
+
const res = {};
|
|
47
|
+
const prototype = Object.getPrototypeOf(scope);
|
|
48
|
+
const infoProps = (typeof prototype === "object" && prototype !== null ? prototype[logInfoProperties] : []) ?? [];
|
|
49
|
+
for (const prop of infoProps) {
|
|
50
|
+
try {
|
|
51
|
+
res[prop] = typeof scope[prop] === "function" ? scope[prop]() : scope[prop];
|
|
52
|
+
} catch (err) {
|
|
53
|
+
res[prop] = err.message;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return res;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// src/context.ts
|
|
60
|
+
var matchFilter = (filter, level, path) => {
|
|
61
|
+
if (filter.pattern?.startsWith("-")) {
|
|
62
|
+
if (path?.includes(filter.pattern.slice(1))) {
|
|
63
|
+
if (level >= filter.level) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
if (filter.pattern?.length) {
|
|
69
|
+
if (path?.includes(filter.pattern)) {
|
|
70
|
+
return level >= filter.level;
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
if (level >= filter.level) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
var shouldLog = (entry, filters) => {
|
|
80
|
+
if (filters === void 0) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const results = filters.map((filter) => matchFilter(filter, entry.level, entry.meta?.F)).filter((result) => result !== void 0);
|
|
84
|
+
return results.length > 0 && !results.some((results2) => results2 === false);
|
|
85
|
+
};
|
|
86
|
+
var getContextFromEntry = (entry) => {
|
|
87
|
+
let context;
|
|
88
|
+
if (entry.meta) {
|
|
89
|
+
const scopeInfo = gatherLogInfoFromScope(entry.meta.S);
|
|
90
|
+
if (Object.keys(scopeInfo).length > 0) {
|
|
91
|
+
context = Object.assign(context ?? {}, scopeInfo);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const entryContext = typeof entry.context === "function" ? entry.context() : entry.context;
|
|
95
|
+
if (entryContext) {
|
|
96
|
+
if (entryContext instanceof Error) {
|
|
97
|
+
const c = entryContext.context;
|
|
98
|
+
context = Object.assign(context ?? {}, {
|
|
99
|
+
error: entryContext.stack,
|
|
100
|
+
...c
|
|
101
|
+
});
|
|
102
|
+
} else if (typeof entryContext === "object") {
|
|
103
|
+
context = Object.assign(context ?? {}, entryContext);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (entry.error) {
|
|
107
|
+
context = Object.assign(context ?? {}, {
|
|
108
|
+
error: entry.error
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
return context && Object.keys(context).length > 0 ? context : void 0;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// src/processors/common.ts
|
|
115
|
+
var getRelativeFilename = (filename) => {
|
|
116
|
+
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
117
|
+
if (match) {
|
|
118
|
+
const [, filePath] = match;
|
|
119
|
+
return filePath;
|
|
120
|
+
}
|
|
121
|
+
return filename;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export {
|
|
125
|
+
LogLevel,
|
|
126
|
+
levels,
|
|
127
|
+
shortLevelName,
|
|
128
|
+
LogProcessorType,
|
|
129
|
+
logInfo,
|
|
130
|
+
gatherLogInfoFromScope,
|
|
131
|
+
shouldLog,
|
|
132
|
+
getContextFromEntry,
|
|
133
|
+
getRelativeFilename
|
|
134
|
+
};
|
|
135
|
+
//# sourceMappingURL=chunk-QPYJZ4SO.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/config.ts", "../../../src/scope.ts", "../../../src/context.ts", "../../../src/processors/common.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\nimport { type LogProcessor } from './context';\n\n/**\n * Standard levels.\n * NOTE: Keep aligned with LogLevel in @dxos/protocols.\n */\n// TODO(burdon): Update numbers?\nexport enum LogLevel {\n TRACE = 5,\n DEBUG = 10,\n VERBOSE = 11,\n INFO = 12,\n WARN = 13,\n ERROR = 14,\n}\n\nexport const levels: Record<string, LogLevel> = {\n '*': LogLevel.TRACE,\n trace: LogLevel.TRACE,\n debug: LogLevel.DEBUG,\n verbose: LogLevel.VERBOSE,\n info: LogLevel.INFO,\n warn: LogLevel.WARN,\n error: LogLevel.ERROR,\n};\n\nexport const shortLevelName = {\n [LogLevel.TRACE]: 'T',\n [LogLevel.DEBUG]: 'D',\n [LogLevel.VERBOSE]: 'V',\n [LogLevel.INFO]: 'I',\n [LogLevel.WARN]: 'W',\n [LogLevel.ERROR]: 'E',\n};\n\nexport enum LogProcessorType {\n CONSOLE = 'console',\n BROWSER = 'browser',\n DEBUG = 'debug',\n}\n\n/**\n * Individual filter condition.\n */\nexport type LogFilter = {\n level: LogLevel;\n pattern?: string;\n};\n\n/**\n * Options to set inline or load from the YML file.\n */\nexport type LogOptions = {\n file?: string;\n filter?: string | string[] | LogLevel;\n captureFilter?: string | string[] | LogLevel;\n depth?: number; // Context object depth.\n processor?: string | LogProcessorType;\n formatter?: {\n column: number;\n timestamp: boolean;\n timestampFirst: boolean;\n };\n prefix?: string;\n};\n\n/**\n * Runtime config.\n */\nexport interface LogConfig {\n options: LogOptions;\n filters?: LogFilter[];\n captureFilters?: LogFilter[];\n processors: LogProcessor[];\n prefix?: string;\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nconst logInfoProperties = Symbol('logInfoProperties');\n\n/**\n * Decorate fields, properties, or methods to automatically include their values in log messages.\n *\n * Example:\n *\n * ```typescript\n * class Example {\n * @logInfo\n * peerId: PublicKey;\n * }\n * ```\n */\nexport const logInfo = (target: any, propertyKey: string, descriptor?: PropertyDescriptor) => {\n // console.log(target, propertyKey, descriptor);\n (target[logInfoProperties] ??= []).push(propertyKey);\n};\n\n/**\n * Introspects class instance to find decorated metadata.\n * @param scope Class instance.\n */\nexport const gatherLogInfoFromScope = (scope: any): Record<string, any> => {\n if (!scope) {\n return {};\n }\n\n const res: Record<string, any> = {};\n\n const prototype = Object.getPrototypeOf(scope);\n const infoProps = (typeof prototype === 'object' && prototype !== null ? prototype[logInfoProperties] : []) ?? [];\n for (const prop of infoProps) {\n try {\n res[prop] = typeof scope[prop] === 'function' ? scope[prop]() : scope[prop];\n } catch (err: any) {\n res[prop] = err.message;\n }\n }\n\n return res;\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type LogConfig, type LogFilter, type LogLevel } from './config';\nimport { type CallMetadata } from './meta';\nimport { gatherLogInfoFromScope } from './scope';\n\n/**\n * Optional object passed to the logging API.\n */\nexport type LogContext = Record<string, any> | Error | any;\n\n/**\n * Record for current log line.\n */\nexport interface LogEntry {\n level: LogLevel;\n message?: string;\n context?: LogContext;\n meta?: CallMetadata;\n error?: Error;\n}\n\n/**\n * Processes (e.g., prints, forwards) log entries.\n */\nexport type LogProcessor = (config: LogConfig, entry: LogEntry) => void;\n\n/**\n * Returns:\n * true if the log entry matches the filter,\n * false if should be excluded, or\n * undefined if it the filter doesn't match the level.\n */\nconst matchFilter = (filter: LogFilter, level: LogLevel, path?: string): boolean | undefined => {\n // TODO(burdon): Support regexp.\n if (filter.pattern?.startsWith('-')) {\n // Exclude.\n if (path?.includes(filter.pattern.slice(1))) {\n if (level >= filter.level) {\n return false;\n }\n }\n } else {\n // Include.\n if (filter.pattern?.length) {\n if (path?.includes(filter.pattern)) {\n return level >= filter.level;\n }\n } else {\n if (level >= filter.level) {\n return true;\n }\n }\n }\n};\n\n/**\n * Determines if the current line should be logged (called by the processor).\n */\nexport const shouldLog = (entry: LogEntry, filters?: LogFilter[]): boolean => {\n if (filters === undefined) {\n return false;\n }\n\n const results = filters\n .map((filter) => matchFilter(filter, entry.level, entry.meta?.F))\n .filter((result): result is boolean => result !== undefined);\n\n // Skip if any are explicitely false.\n // console.log({ level: entry.level, path: entry.meta?.F }, filters, results, results.length);\n return results.length > 0 && !results.some((results) => results === false);\n};\n\nexport const getContextFromEntry = (entry: LogEntry): Record<string, any> | undefined => {\n let context;\n if (entry.meta) {\n const scopeInfo = gatherLogInfoFromScope(entry.meta.S);\n if (Object.keys(scopeInfo).length > 0) {\n context = Object.assign(context ?? {}, scopeInfo);\n }\n }\n\n const entryContext = typeof entry.context === 'function' ? entry.context() : entry.context;\n if (entryContext) {\n if (entryContext instanceof Error) {\n // Additional context from Error.\n const c = (entryContext as any).context;\n // If ERROR then show stacktrace.\n context = Object.assign(context ?? {}, { error: entryContext.stack, ...c });\n } else if (typeof entryContext === 'object') {\n context = Object.assign(context ?? {}, entryContext);\n }\n }\n\n if (entry.error) {\n context = Object.assign(context ?? {}, { error: entry.error });\n }\n\n return context && Object.keys(context).length > 0 ? context : undefined;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nexport const getRelativeFilename = (filename: string) => {\n // TODO(burdon): Hack uses \"packages\" as an anchor (pre-parse NX?)\n // Including `packages/` part of the path so that excluded paths (e.g. from dist) are clickable in vscode.\n const match = filename.match(/.+\\/(packages\\/.+\\/.+)/);\n if (match) {\n const [, filePath] = match;\n return filePath;\n }\n\n return filename;\n};\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["LogLevel", "levels", "trace", "debug", "verbose", "info", "warn", "error", "shortLevelName", "LogProcessorType", "logInfoProperties", "Symbol", "logInfo", "target", "propertyKey", "descriptor", "push", "gatherLogInfoFromScope", "scope", "res", "prototype", "Object", "getPrototypeOf", "infoProps", "prop", "err", "message", "matchFilter", "filter", "level", "path", "pattern", "startsWith", "includes", "slice", "length", "shouldLog", "entry", "filters", "undefined", "results", "map", "meta", "F", "result", "some", "getContextFromEntry", "context", "scopeInfo", "gatherLogInfoFromScope", "S", "Object", "keys", "assign", "entryContext", "Error", "c", "error", "stack", "getRelativeFilename", "filename", "match", "filePath"]
|
|
7
|
+
}
|
|
@@ -1,106 +1,50 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
LogLevel,
|
|
4
|
+
LogProcessorType,
|
|
5
|
+
gatherLogInfoFromScope,
|
|
6
|
+
getContextFromEntry,
|
|
7
|
+
getRelativeFilename,
|
|
8
|
+
levels,
|
|
9
|
+
logInfo,
|
|
10
|
+
shortLevelName,
|
|
11
|
+
shouldLog
|
|
12
|
+
} from "./chunk-QPYJZ4SO.mjs";
|
|
13
|
+
import {
|
|
14
|
+
__export,
|
|
15
|
+
__reExport
|
|
16
|
+
} from "./chunk-2SZHAWBN.mjs";
|
|
2
17
|
|
|
3
18
|
// src/index.ts
|
|
19
|
+
var index_exports = {};
|
|
20
|
+
__export(index_exports, {
|
|
21
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
22
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
23
|
+
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
24
|
+
LogLevel: () => LogLevel,
|
|
25
|
+
LogProcessorType: () => LogProcessorType,
|
|
26
|
+
createFileProcessor: () => createFileProcessor,
|
|
27
|
+
createLog: () => createLog,
|
|
28
|
+
debug: () => debug,
|
|
29
|
+
gatherLogInfoFromScope: () => gatherLogInfoFromScope,
|
|
30
|
+
getContextFromEntry: () => getContextFromEntry,
|
|
31
|
+
getCurrentOwnershipScope: () => getCurrentOwnershipScope,
|
|
32
|
+
getRelativeFilename: () => getRelativeFilename,
|
|
33
|
+
levels: () => levels,
|
|
34
|
+
log: () => log,
|
|
35
|
+
logInfo: () => logInfo,
|
|
36
|
+
omit: () => omit,
|
|
37
|
+
parseFilter: () => parseFilter,
|
|
38
|
+
pick: () => pick,
|
|
39
|
+
shortLevelName: () => shortLevelName,
|
|
40
|
+
shouldLog: () => shouldLog
|
|
41
|
+
});
|
|
4
42
|
import omit from "lodash.omit";
|
|
5
43
|
import { pick } from "@dxos/util";
|
|
6
44
|
|
|
7
|
-
// src/config.ts
|
|
8
|
-
var LogLevel = /* @__PURE__ */ function(LogLevel2) {
|
|
9
|
-
LogLevel2[LogLevel2["TRACE"] = 5] = "TRACE";
|
|
10
|
-
LogLevel2[LogLevel2["DEBUG"] = 10] = "DEBUG";
|
|
11
|
-
LogLevel2[LogLevel2["VERBOSE"] = 11] = "VERBOSE";
|
|
12
|
-
LogLevel2[LogLevel2["INFO"] = 12] = "INFO";
|
|
13
|
-
LogLevel2[LogLevel2["WARN"] = 13] = "WARN";
|
|
14
|
-
LogLevel2[LogLevel2["ERROR"] = 14] = "ERROR";
|
|
15
|
-
return LogLevel2;
|
|
16
|
-
}({});
|
|
17
|
-
var levels = {
|
|
18
|
-
trace: 5,
|
|
19
|
-
debug: 10,
|
|
20
|
-
verbose: 11,
|
|
21
|
-
info: 12,
|
|
22
|
-
warn: 13,
|
|
23
|
-
error: 14
|
|
24
|
-
};
|
|
25
|
-
var shortLevelName = {
|
|
26
|
-
[5]: "T",
|
|
27
|
-
[10]: "D",
|
|
28
|
-
[11]: "V",
|
|
29
|
-
[12]: "I",
|
|
30
|
-
[13]: "W",
|
|
31
|
-
[14]: "E"
|
|
32
|
-
};
|
|
33
|
-
var LogProcessorType = /* @__PURE__ */ function(LogProcessorType2) {
|
|
34
|
-
LogProcessorType2["CONSOLE"] = "console";
|
|
35
|
-
LogProcessorType2["BROWSER"] = "browser";
|
|
36
|
-
LogProcessorType2["DEBUG"] = "debug";
|
|
37
|
-
return LogProcessorType2;
|
|
38
|
-
}({});
|
|
39
|
-
|
|
40
|
-
// src/scope.ts
|
|
41
|
-
var logInfoProperties = Symbol("logInfoProperties");
|
|
42
|
-
var logInfo = (target, propertyKey, descriptor) => {
|
|
43
|
-
(target[logInfoProperties] ??= []).push(propertyKey);
|
|
44
|
-
};
|
|
45
|
-
var gatherLogInfoFromScope = (scope) => {
|
|
46
|
-
if (!scope) {
|
|
47
|
-
return {};
|
|
48
|
-
}
|
|
49
|
-
const res = {};
|
|
50
|
-
const prototype = Object.getPrototypeOf(scope);
|
|
51
|
-
const infoProps = prototype[logInfoProperties] ?? [];
|
|
52
|
-
for (const prop of infoProps) {
|
|
53
|
-
try {
|
|
54
|
-
res[prop] = typeof scope[prop] === "function" ? scope[prop]() : scope[prop];
|
|
55
|
-
} catch (err) {
|
|
56
|
-
res[prop] = err.message;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return res;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
// src/context.ts
|
|
63
|
-
var matchFilter = (filter, level, path) => {
|
|
64
|
-
return level >= filter.level && (!filter.pattern || path.includes(filter.pattern));
|
|
65
|
-
};
|
|
66
|
-
var shouldLog = (entry, filters) => {
|
|
67
|
-
if (filters === void 0) {
|
|
68
|
-
return true;
|
|
69
|
-
} else {
|
|
70
|
-
return filters.some((filter) => matchFilter(filter, entry.level, entry.meta?.F ?? ""));
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
var getContextFromEntry = (entry) => {
|
|
74
|
-
let context;
|
|
75
|
-
if (entry.meta) {
|
|
76
|
-
const scopeInfo = gatherLogInfoFromScope(entry.meta.S);
|
|
77
|
-
if (Object.keys(scopeInfo).length > 0) {
|
|
78
|
-
context = Object.assign(context ?? {}, scopeInfo);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
const entryContext = typeof entry.context === "function" ? entry.context() : entry.context;
|
|
82
|
-
if (entryContext) {
|
|
83
|
-
if (entryContext instanceof Error) {
|
|
84
|
-
const c = entryContext.context;
|
|
85
|
-
context = Object.assign(context ?? {}, {
|
|
86
|
-
error: entryContext.stack,
|
|
87
|
-
...c
|
|
88
|
-
});
|
|
89
|
-
} else if (typeof entryContext === "object") {
|
|
90
|
-
context = Object.assign(context ?? {}, entryContext);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (entry.error) {
|
|
94
|
-
context = Object.assign(context ?? {}, {
|
|
95
|
-
error: entry.error
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return context && Object.keys(context).length > 0 ? context : void 0;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
45
|
// src/decorators.ts
|
|
102
|
-
import chalk from "chalk";
|
|
103
46
|
import { inspect } from "node:util";
|
|
47
|
+
import chalk from "chalk";
|
|
104
48
|
var nextPromiseId = 0;
|
|
105
49
|
var createMethodLogDecorator = (log2) => (arg0, arg1, meta) => (target, propertyKey, descriptor) => {
|
|
106
50
|
const method = descriptor.value;
|
|
@@ -197,142 +141,33 @@ var logAsyncResolved = (log2, methodName, resolvedValue, promiseId, startTime, c
|
|
|
197
141
|
var logAsyncRejected = (log2, methodName, err, promiseId, startTime, combinedMeta) => {
|
|
198
142
|
log2.info(`.${formatFunction(methodName)} \u21B2 \u{1F525} ${chalk.gray("reject")} ${formatPromise(promiseId)} ${formatTimeElapsed(startTime)} ${chalk.gray("=>")} ${err}`, {}, combinedMeta);
|
|
199
143
|
};
|
|
200
|
-
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
201
|
-
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
202
144
|
var COLOR_FUNCTION = [
|
|
203
145
|
220,
|
|
204
146
|
220,
|
|
205
147
|
170
|
|
206
148
|
];
|
|
149
|
+
var greenCheck = typeof chalk.green === "function" ? chalk.green("\u2714") : "\u2714";
|
|
150
|
+
var formatTimeElapsed = (startTime) => chalk.gray(`${(performance.now() - startTime).toFixed(0)}ms`);
|
|
207
151
|
var formatFunction = (name) => chalk.bold(chalk.rgb(...COLOR_FUNCTION)(name));
|
|
208
152
|
var formatPromise = (id) => chalk.blue(`Promise#${id}`);
|
|
209
153
|
|
|
210
154
|
// src/options.ts
|
|
211
155
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
212
156
|
|
|
213
|
-
// src/platform/
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
if (filepath) {
|
|
218
|
-
try {
|
|
219
|
-
const text = fs.readFileSync(filepath, "utf-8");
|
|
220
|
-
if (text) {
|
|
221
|
-
return yaml.load(text);
|
|
222
|
-
}
|
|
223
|
-
} catch (err) {
|
|
224
|
-
console.warn(`Invalid log file: ${filepath}`);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
};
|
|
157
|
+
// src/platform/index.ts
|
|
158
|
+
var platform_exports = {};
|
|
159
|
+
__reExport(platform_exports, platform_star);
|
|
160
|
+
import * as platform_star from "#platform";
|
|
228
161
|
|
|
229
|
-
// src/processors/
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const [, filePath] = match;
|
|
239
|
-
return filePath;
|
|
240
|
-
}
|
|
241
|
-
return filename;
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
// src/processors/console-processor.ts
|
|
245
|
-
var LEVEL_COLORS = {
|
|
246
|
-
[LogLevel.TRACE]: "gray",
|
|
247
|
-
[LogLevel.DEBUG]: "gray",
|
|
248
|
-
[LogLevel.VERBOSE]: "gray",
|
|
249
|
-
[LogLevel.INFO]: "white",
|
|
250
|
-
[LogLevel.WARN]: "yellow",
|
|
251
|
-
[LogLevel.ERROR]: "red"
|
|
252
|
-
};
|
|
253
|
-
var truncate = (text, length = 0, right = false) => {
|
|
254
|
-
const str = text && length ? right ? text.slice(-length) : text.substring(0, length) : text ?? "";
|
|
255
|
-
return right ? str.padStart(length, " ") : str.padEnd(length, " ");
|
|
256
|
-
};
|
|
257
|
-
var DEFAULT_FORMATTER = (config, { path, line, level, message, context, error, scope }) => {
|
|
258
|
-
const column = config.options?.formatter?.column;
|
|
259
|
-
const filepath = path !== void 0 && line !== void 0 ? chalk2.grey(`${path}:${line}`) : void 0;
|
|
260
|
-
let instance;
|
|
261
|
-
if (scope) {
|
|
262
|
-
const prototype = Object.getPrototypeOf(scope);
|
|
263
|
-
const id = getPrototypeSpecificInstanceId(scope);
|
|
264
|
-
instance = chalk2.magentaBright(`${prototype.constructor.name}#${id}`);
|
|
265
|
-
}
|
|
266
|
-
const formattedTimestamp = config.options?.formatter?.timestamp ? (/* @__PURE__ */ new Date()).toISOString() : void 0;
|
|
267
|
-
const formattedLevel = chalk2[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]);
|
|
268
|
-
const padding = column && filepath ? "".padStart(column - filepath.length) : void 0;
|
|
269
|
-
return config.options?.formatter?.timestampFirst ? [
|
|
270
|
-
formattedTimestamp,
|
|
271
|
-
filepath,
|
|
272
|
-
padding,
|
|
273
|
-
formattedLevel,
|
|
274
|
-
instance,
|
|
275
|
-
message,
|
|
276
|
-
context,
|
|
277
|
-
error
|
|
278
|
-
] : [
|
|
279
|
-
// NOTE: File path must come fist for console hyperlinks.
|
|
280
|
-
// Must not truncate for terminal output.
|
|
281
|
-
filepath,
|
|
282
|
-
padding,
|
|
283
|
-
formattedTimestamp,
|
|
284
|
-
formattedLevel,
|
|
285
|
-
instance,
|
|
286
|
-
message,
|
|
287
|
-
context,
|
|
288
|
-
error
|
|
289
|
-
];
|
|
290
|
-
};
|
|
291
|
-
var SHORT_FORMATTER = (config, { path, level, message }) => {
|
|
292
|
-
return [
|
|
293
|
-
chalk2.grey(truncate(path, 16, true)),
|
|
294
|
-
chalk2[LEVEL_COLORS[level]](shortLevelName[level]),
|
|
295
|
-
message
|
|
296
|
-
];
|
|
297
|
-
};
|
|
298
|
-
var formatter = DEFAULT_FORMATTER;
|
|
299
|
-
var CONSOLE_PROCESSOR = (config, entry) => {
|
|
300
|
-
const { level, message, meta, error } = entry;
|
|
301
|
-
if (!shouldLog(entry, config.filters)) {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
const parts = {
|
|
305
|
-
level,
|
|
306
|
-
message,
|
|
307
|
-
error,
|
|
308
|
-
path: void 0,
|
|
309
|
-
line: void 0,
|
|
310
|
-
scope: void 0,
|
|
311
|
-
context: void 0
|
|
312
|
-
};
|
|
313
|
-
if (meta) {
|
|
314
|
-
parts.path = getRelativeFilename(meta.F);
|
|
315
|
-
parts.line = meta.L;
|
|
316
|
-
parts.scope = meta.S;
|
|
317
|
-
}
|
|
318
|
-
const context = getContextFromEntry(entry);
|
|
319
|
-
if (context) {
|
|
320
|
-
parts.context = inspect2(pickBy(context, (value) => value !== void 0), {
|
|
321
|
-
depth: config.options.depth,
|
|
322
|
-
colors: true,
|
|
323
|
-
maxArrayLength: 8,
|
|
324
|
-
sorted: false
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
const line = formatter(config, parts).filter(Boolean).join(" ");
|
|
328
|
-
console.log(line);
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
// src/processors/debug-processor.ts
|
|
332
|
-
import { inspect as inspect3 } from "node:util";
|
|
333
|
-
var DEBUG_PROCESSOR = (config, entry) => {
|
|
334
|
-
console.log(inspect3(entry, false, null, true));
|
|
335
|
-
};
|
|
162
|
+
// src/processors/index.ts
|
|
163
|
+
var processors_exports = {};
|
|
164
|
+
__export(processors_exports, {
|
|
165
|
+
BROWSER_PROCESSOR: () => BROWSER_PROCESSOR,
|
|
166
|
+
DEBUG_PROCESSOR: () => DEBUG_PROCESSOR,
|
|
167
|
+
FILE_PROCESSOR: () => FILE_PROCESSOR,
|
|
168
|
+
createFileProcessor: () => createFileProcessor,
|
|
169
|
+
getRelativeFilename: () => getRelativeFilename
|
|
170
|
+
});
|
|
336
171
|
|
|
337
172
|
// src/processors/browser-processor.ts
|
|
338
173
|
import { getDebugName, safariCheck } from "@dxos/util";
|
|
@@ -374,6 +209,8 @@ var APP_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
374
209
|
if (context) {
|
|
375
210
|
if (Object.keys(context).length === 1 && "error" in context) {
|
|
376
211
|
args.push(context.error);
|
|
212
|
+
} else if (Object.keys(context).length === 1 && "err" in context) {
|
|
213
|
+
args.push(context.err);
|
|
377
214
|
} else {
|
|
378
215
|
args.push(context);
|
|
379
216
|
}
|
|
@@ -439,6 +276,16 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
439
276
|
};
|
|
440
277
|
var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
441
278
|
|
|
279
|
+
// src/processors/index.ts
|
|
280
|
+
__reExport(processors_exports, console_processor_star);
|
|
281
|
+
import * as console_processor_star from "#console-processor";
|
|
282
|
+
|
|
283
|
+
// src/processors/debug-processor.ts
|
|
284
|
+
import { inspect as inspect2 } from "node:util";
|
|
285
|
+
var DEBUG_PROCESSOR = (config, entry) => {
|
|
286
|
+
console.log(inspect2(entry, false, null, true));
|
|
287
|
+
};
|
|
288
|
+
|
|
442
289
|
// src/processors/file-processor.ts
|
|
443
290
|
import { appendFileSync, mkdirSync, openSync } from "node:fs";
|
|
444
291
|
import { dirname } from "node:path";
|
|
@@ -510,14 +357,15 @@ var FILE_PROCESSOR = createFileProcessor({
|
|
|
510
357
|
|
|
511
358
|
// src/options.ts
|
|
512
359
|
var processors = {
|
|
513
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
360
|
+
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
514
361
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
515
362
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
516
363
|
};
|
|
517
|
-
var
|
|
364
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
518
365
|
var DEFAULT_PROCESSORS = [
|
|
519
|
-
|
|
366
|
+
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
520
367
|
];
|
|
368
|
+
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
521
369
|
var parseFilter = (filter) => {
|
|
522
370
|
if (typeof filter === "number") {
|
|
523
371
|
return [
|
|
@@ -526,7 +374,6 @@ var parseFilter = (filter) => {
|
|
|
526
374
|
}
|
|
527
375
|
];
|
|
528
376
|
}
|
|
529
|
-
const parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
530
377
|
const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
|
|
531
378
|
return lines.map((filter2) => {
|
|
532
379
|
const [pattern, level] = filter2.split(":");
|
|
@@ -538,54 +385,37 @@ var parseFilter = (filter) => {
|
|
|
538
385
|
};
|
|
539
386
|
});
|
|
540
387
|
};
|
|
541
|
-
var
|
|
542
|
-
const
|
|
388
|
+
var createConfig = (options) => {
|
|
389
|
+
const envOptions = "process" in globalThis ? {
|
|
543
390
|
file: process.env.LOG_CONFIG,
|
|
544
391
|
filter: process.env.LOG_FILTER,
|
|
545
392
|
processor: process.env.LOG_PROCESSOR
|
|
546
393
|
} : void 0;
|
|
547
|
-
const mergedOptions = defaultsDeep({}, loadOptions(
|
|
394
|
+
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
548
395
|
return {
|
|
549
396
|
options: mergedOptions,
|
|
550
397
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
551
398
|
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
552
399
|
processors: mergedOptions.processor ? [
|
|
553
400
|
processors[mergedOptions.processor]
|
|
554
|
-
] :
|
|
401
|
+
] : [
|
|
402
|
+
...DEFAULT_PROCESSORS
|
|
403
|
+
],
|
|
555
404
|
prefix: mergedOptions.prefix
|
|
556
405
|
};
|
|
557
406
|
};
|
|
558
407
|
|
|
559
408
|
// src/log.ts
|
|
409
|
+
var logCount = 0;
|
|
560
410
|
var createLog = () => {
|
|
561
411
|
const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
562
|
-
log2
|
|
412
|
+
Object.assign(log2, {
|
|
413
|
+
_id: `log-${++logCount}`,
|
|
414
|
+
_config: createConfig()
|
|
415
|
+
});
|
|
563
416
|
Object.defineProperty(log2, "runtimeConfig", {
|
|
564
417
|
get: () => log2._config
|
|
565
418
|
});
|
|
566
|
-
log2.addProcessor = (processor) => {
|
|
567
|
-
if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
|
|
568
|
-
DEFAULT_PROCESSORS.push(processor);
|
|
569
|
-
}
|
|
570
|
-
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
571
|
-
log2._config.processors.push(processor);
|
|
572
|
-
}
|
|
573
|
-
};
|
|
574
|
-
log2.config = (options) => {
|
|
575
|
-
log2._config = getConfig(options);
|
|
576
|
-
};
|
|
577
|
-
log2.trace = (...params) => processLog(LogLevel.TRACE, ...params);
|
|
578
|
-
log2.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
579
|
-
log2.verbose = (...params) => processLog(LogLevel.VERBOSE, ...params);
|
|
580
|
-
log2.info = (...params) => processLog(LogLevel.INFO, ...params);
|
|
581
|
-
log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
|
|
582
|
-
log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
583
|
-
log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error);
|
|
584
|
-
log2.break = () => log2.info("\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014");
|
|
585
|
-
log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
586
|
-
${getFormattedStackTrace()}`, context, meta);
|
|
587
|
-
log2.method = createMethodLogDecorator(log2);
|
|
588
|
-
log2.func = createFunctionLogDecorator(log2);
|
|
589
419
|
const processLog = (level, message, context = {}, meta, error) => {
|
|
590
420
|
log2._config.processors.forEach((processor) => processor(log2._config, {
|
|
591
421
|
level,
|
|
@@ -595,9 +425,50 @@ ${getFormattedStackTrace()}`, context, meta);
|
|
|
595
425
|
error
|
|
596
426
|
}));
|
|
597
427
|
};
|
|
428
|
+
Object.assign(log2, {
|
|
429
|
+
/**
|
|
430
|
+
* Update config.
|
|
431
|
+
* NOTE: Preserves any processors that were already added to this logger instance
|
|
432
|
+
* unless an explicit processor option is provided.
|
|
433
|
+
*/
|
|
434
|
+
config: ({ processor, ...options }) => {
|
|
435
|
+
const config = createConfig(options);
|
|
436
|
+
const processors2 = processor ? config.processors : log2._config.processors;
|
|
437
|
+
log2._config = {
|
|
438
|
+
...config,
|
|
439
|
+
processors: processors2
|
|
440
|
+
};
|
|
441
|
+
return log2;
|
|
442
|
+
},
|
|
443
|
+
/**
|
|
444
|
+
* Adds a processor to the logger.
|
|
445
|
+
*/
|
|
446
|
+
addProcessor: (processor) => {
|
|
447
|
+
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
448
|
+
log2._config.processors.push(processor);
|
|
449
|
+
}
|
|
450
|
+
return () => {
|
|
451
|
+
log2._config.processors = log2._config.processors.filter((p) => p !== processor);
|
|
452
|
+
};
|
|
453
|
+
},
|
|
454
|
+
trace: (...params) => processLog(LogLevel.TRACE, ...params),
|
|
455
|
+
debug: (...params) => processLog(LogLevel.DEBUG, ...params),
|
|
456
|
+
verbose: (...params) => processLog(LogLevel.VERBOSE, ...params),
|
|
457
|
+
info: (...params) => processLog(LogLevel.INFO, ...params),
|
|
458
|
+
warn: (...params) => processLog(LogLevel.WARN, ...params),
|
|
459
|
+
error: (...params) => processLog(LogLevel.ERROR, ...params),
|
|
460
|
+
catch: (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error),
|
|
461
|
+
method: createMethodLogDecorator(log2),
|
|
462
|
+
function: createFunctionLogDecorator(log2),
|
|
463
|
+
break: () => log2.info("-".repeat(80)),
|
|
464
|
+
stack: (message, context, meta) => {
|
|
465
|
+
return processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
466
|
+
${getFormattedStackTrace()}`, context, meta);
|
|
467
|
+
}
|
|
468
|
+
});
|
|
598
469
|
return log2;
|
|
599
470
|
};
|
|
600
|
-
var log = globalThis.
|
|
471
|
+
var log = globalThis.DX_LOG ??= createLog();
|
|
601
472
|
var start = Date.now();
|
|
602
473
|
var last = start;
|
|
603
474
|
var debug = (label, args) => {
|
|
@@ -614,12 +485,18 @@ var debug = (label, args) => {
|
|
|
614
485
|
};
|
|
615
486
|
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
616
487
|
|
|
488
|
+
// src/index.ts
|
|
489
|
+
__reExport(index_exports, processors_exports);
|
|
490
|
+
|
|
617
491
|
// src/experimental/ownership.ts
|
|
618
|
-
import { inspect as
|
|
492
|
+
import { inspect as inspect3 } from "node:util";
|
|
619
493
|
var kOwnershipScope = Symbol("kOwnershipScope");
|
|
620
494
|
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
621
495
|
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
622
496
|
var OwnershipScope = class {
|
|
497
|
+
constr;
|
|
498
|
+
parent;
|
|
499
|
+
instance;
|
|
623
500
|
constructor(constr, parent) {
|
|
624
501
|
this.constr = constr;
|
|
625
502
|
this.parent = parent;
|
|
@@ -635,7 +512,7 @@ var OwnershipScope = class {
|
|
|
635
512
|
}
|
|
636
513
|
return info;
|
|
637
514
|
}
|
|
638
|
-
[
|
|
515
|
+
[inspect3.custom]() {
|
|
639
516
|
return {
|
|
640
517
|
className: this.constr.name,
|
|
641
518
|
info: this.getInfo(),
|
|
@@ -646,14 +523,12 @@ var OwnershipScope = class {
|
|
|
646
523
|
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
647
524
|
export {
|
|
648
525
|
BROWSER_PROCESSOR,
|
|
649
|
-
CONSOLE_PROCESSOR,
|
|
650
526
|
DEBUG_PROCESSOR,
|
|
651
|
-
DEFAULT_FORMATTER,
|
|
652
527
|
FILE_PROCESSOR,
|
|
653
528
|
LogLevel,
|
|
654
529
|
LogProcessorType,
|
|
655
|
-
SHORT_FORMATTER,
|
|
656
530
|
createFileProcessor,
|
|
531
|
+
createLog,
|
|
657
532
|
debug,
|
|
658
533
|
gatherLogInfoFromScope,
|
|
659
534
|
getContextFromEntry,
|
|
@@ -666,7 +541,6 @@ export {
|
|
|
666
541
|
parseFilter,
|
|
667
542
|
pick,
|
|
668
543
|
shortLevelName,
|
|
669
|
-
shouldLog
|
|
670
|
-
truncate
|
|
544
|
+
shouldLog
|
|
671
545
|
};
|
|
672
546
|
//# sourceMappingURL=index.mjs.map
|