@dxos/log 0.8.4-main.548089c → 0.8.4-main.59c2e9b
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 +130 -176
- 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 +127 -260
- 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.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/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 +29 -9
- package/src/config.ts +1 -0
- package/src/context.ts +36 -5
- package/src/decorators.ts +3 -3
- package/src/log.test.ts +48 -18
- package/src/log.ts +101 -57
- package/src/options.ts +26 -10
- package/src/platform/index.ts +1 -1
- package/src/processors/file-processor.ts +2 -0
- package/src/processors/index.ts +3 -3
|
@@ -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": ";;;AAWO,IAAKA,WAAAA,0BAAAA,WAAAA;;;;;;;SAAAA;;AASL,IAAMC,SAAmC;EAC9C,KAAG;EACHC,OAAK;EACLC,OAAK;EACLC,SAAO;EACPC,MAAI;EACJC,MAAI;EACJC,OAAK;AACP;AAEO,IAAMC,iBAAiB;EAC5B,CAAA,CAAA,GAAkB;EAClB,CAAA,EAAA,GAAkB;EAClB,CAAA,EAAA,GAAoB;EACpB,CAAA,EAAA,GAAiB;EACjB,CAAA,EAAA,GAAiB;EACjB,CAAA,EAAA,GAAkB;AACpB;AAEO,IAAKC,mBAAAA,0BAAAA,mBAAAA;;;;SAAAA;;;;ACnCZ,IAAMC,oBAAoBC,OAAO,mBAAA;AAc1B,IAAMC,UAAU,CAACC,QAAaC,aAAqBC,eAAAA;AAEvDF,GAAAA,OAAOH,iBAAAA,MAAuB,CAAA,GAAIM,KAAKF,WAAAA;AAC1C;AAMO,IAAMG,yBAAyB,CAACC,UAAAA;AACrC,MAAI,CAACA,OAAO;AACV,WAAO,CAAC;EACV;AAEA,QAAMC,MAA2B,CAAC;AAElC,QAAMC,YAAYC,OAAOC,eAAeJ,KAAAA;AACxC,QAAMK,aAAa,OAAOH,cAAc,YAAYA,cAAc,OAAOA,UAAUV,iBAAAA,IAAqB,CAAA,MAAO,CAAA;AAC/G,aAAWc,QAAQD,WAAW;AAC5B,QAAI;AACFJ,UAAIK,IAAAA,IAAQ,OAAON,MAAMM,IAAAA,MAAU,aAAaN,MAAMM,IAAAA,EAAK,IAAKN,MAAMM,IAAAA;IACxE,SAASC,KAAU;AACjBN,UAAIK,IAAAA,IAAQC,IAAIC;IAClB;EACF;AAEA,SAAOP;AACT;;;ACVA,IAAMQ,cAAc,CAACC,QAAmBC,OAAiBC,SAAAA;AAEvD,MAAIF,OAAOG,SAASC,WAAW,GAAA,GAAM;AAEnC,QAAIF,MAAMG,SAASL,OAAOG,QAAQG,MAAM,CAAA,CAAA,GAAK;AAC3C,UAAIL,SAASD,OAAOC,OAAO;AACzB,eAAO;MACT;IACF;EACF,OAAO;AAEL,QAAID,OAAOG,SAASI,QAAQ;AAC1B,UAAIL,MAAMG,SAASL,OAAOG,OAAO,GAAG;AAClC,eAAOF,SAASD,OAAOC;MACzB;IACF,OAAO;AACL,UAAIA,SAASD,OAAOC,OAAO;AACzB,eAAO;MACT;IACF;EACF;AACF;AAKO,IAAMO,YAAY,CAACC,OAAiBC,YAAAA;AACzC,MAAIA,YAAYC,QAAW;AACzB,WAAO;EACT;AAEA,QAAMC,UAAUF,QACbG,IAAI,CAACb,WAAWD,YAAYC,QAAQS,MAAMR,OAAOQ,MAAMK,MAAMC,CAAAA,CAAAA,EAC7Df,OAAO,CAACgB,WAA8BA,WAAWL,MAAAA;AAIpD,SAAOC,QAAQL,SAAS,KAAK,CAACK,QAAQK,KAAK,CAACL,aAAYA,aAAY,KAAA;AACtE;AAEO,IAAMM,sBAAsB,CAACT,UAAAA;AAClC,MAAIU;AACJ,MAAIV,MAAMK,MAAM;AACd,UAAMM,YAAYC,uBAAuBZ,MAAMK,KAAKQ,CAAC;AACrD,QAAIC,OAAOC,KAAKJ,SAAAA,EAAWb,SAAS,GAAG;AACrCY,gBAAUI,OAAOE,OAAON,WAAW,CAAC,GAAGC,SAAAA;IACzC;EACF;AAEA,QAAMM,eAAe,OAAOjB,MAAMU,YAAY,aAAaV,MAAMU,QAAO,IAAKV,MAAMU;AACnF,MAAIO,cAAc;AAChB,QAAIA,wBAAwBC,OAAO;AAEjC,YAAMC,IAAKF,aAAqBP;AAEhCA,gBAAUI,OAAOE,OAAON,WAAW,CAAC,GAAG;QAAEU,OAAOH,aAAaI;QAAO,GAAGF;MAAE,CAAA;IAC3E,WAAW,OAAOF,iBAAiB,UAAU;AAC3CP,gBAAUI,OAAOE,OAAON,WAAW,CAAC,GAAGO,YAAAA;IACzC;EACF;AAEA,MAAIjB,MAAMoB,OAAO;AACfV,cAAUI,OAAOE,OAAON,WAAW,CAAC,GAAG;MAAEU,OAAOpB,MAAMoB;IAAM,CAAA;EAC9D;AAEA,SAAOV,WAAWI,OAAOC,KAAKL,OAAAA,EAASZ,SAAS,IAAIY,UAAUR;AAChE;;;ACjGO,IAAMoB,sBAAsB,CAACC,aAAAA;AAGlC,QAAMC,QAAQD,SAASC,MAAM,wBAAA;AAC7B,MAAIA,OAAO;AACT,UAAM,CAAA,EAAGC,QAAAA,IAAYD;AACrB,WAAOC;EACT;AAEA,SAAOF;AACT;",
|
|
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,103 +1,47 @@
|
|
|
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 = (typeof prototype === "object" && prototype !== null ? 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
46
|
import { inspect } from "node:util";
|
|
103
47
|
import chalk from "chalk";
|
|
@@ -197,144 +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
|
-
};
|
|
228
|
-
|
|
229
|
-
// src/processors/console-processor.ts
|
|
230
|
-
import { inspect as inspect2 } from "node:util";
|
|
231
|
-
import chalk2 from "chalk";
|
|
232
|
-
import { getPrototypeSpecificInstanceId, pickBy } from "@dxos/util";
|
|
233
|
-
|
|
234
|
-
// src/processors/common.ts
|
|
235
|
-
var getRelativeFilename = (filename) => {
|
|
236
|
-
const match = filename.match(/.+\/(packages\/.+\/.+)/);
|
|
237
|
-
if (match) {
|
|
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
|
-
if (prototype !== null) {
|
|
264
|
-
const id = getPrototypeSpecificInstanceId(scope);
|
|
265
|
-
instance = chalk2.magentaBright(`${prototype.constructor.name}#${id}`);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
const formattedTimestamp = config.options?.formatter?.timestamp ? (/* @__PURE__ */ new Date()).toISOString() : void 0;
|
|
269
|
-
const formattedLevel = chalk2[LEVEL_COLORS[level]](column ? shortLevelName[level] : LogLevel[level]);
|
|
270
|
-
const padding = column && filepath ? "".padStart(column - filepath.length) : void 0;
|
|
271
|
-
return config.options?.formatter?.timestampFirst ? [
|
|
272
|
-
formattedTimestamp,
|
|
273
|
-
filepath,
|
|
274
|
-
padding,
|
|
275
|
-
formattedLevel,
|
|
276
|
-
instance,
|
|
277
|
-
message,
|
|
278
|
-
context,
|
|
279
|
-
error
|
|
280
|
-
] : [
|
|
281
|
-
// NOTE: File path must come fist for console hyperlinks.
|
|
282
|
-
// Must not truncate for terminal output.
|
|
283
|
-
filepath,
|
|
284
|
-
padding,
|
|
285
|
-
formattedTimestamp,
|
|
286
|
-
formattedLevel,
|
|
287
|
-
instance,
|
|
288
|
-
message,
|
|
289
|
-
context,
|
|
290
|
-
error
|
|
291
|
-
];
|
|
292
|
-
};
|
|
293
|
-
var SHORT_FORMATTER = (config, { path, level, message }) => {
|
|
294
|
-
return [
|
|
295
|
-
chalk2.grey(truncate(path, 16, true)),
|
|
296
|
-
chalk2[LEVEL_COLORS[level]](shortLevelName[level]),
|
|
297
|
-
message
|
|
298
|
-
];
|
|
299
|
-
};
|
|
300
|
-
var formatter = DEFAULT_FORMATTER;
|
|
301
|
-
var CONSOLE_PROCESSOR = (config, entry) => {
|
|
302
|
-
const { level, message, meta, error } = entry;
|
|
303
|
-
if (!shouldLog(entry, config.filters)) {
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
const parts = {
|
|
307
|
-
level,
|
|
308
|
-
message,
|
|
309
|
-
error,
|
|
310
|
-
path: void 0,
|
|
311
|
-
line: void 0,
|
|
312
|
-
scope: void 0,
|
|
313
|
-
context: void 0
|
|
314
|
-
};
|
|
315
|
-
if (meta) {
|
|
316
|
-
parts.path = getRelativeFilename(meta.F);
|
|
317
|
-
parts.line = meta.L;
|
|
318
|
-
parts.scope = meta.S;
|
|
319
|
-
}
|
|
320
|
-
const context = getContextFromEntry(entry);
|
|
321
|
-
if (context) {
|
|
322
|
-
parts.context = inspect2(pickBy(context, (value) => value !== void 0), {
|
|
323
|
-
depth: config.options.depth,
|
|
324
|
-
colors: true,
|
|
325
|
-
maxArrayLength: 8,
|
|
326
|
-
sorted: false
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
const line = formatter(config, parts).filter(Boolean).join(" ");
|
|
330
|
-
console.log(line);
|
|
331
|
-
};
|
|
157
|
+
// src/platform/index.ts
|
|
158
|
+
var platform_exports = {};
|
|
159
|
+
__reExport(platform_exports, platform_star);
|
|
160
|
+
import * as platform_star from "#platform";
|
|
332
161
|
|
|
333
|
-
// src/processors/
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
+
});
|
|
338
171
|
|
|
339
172
|
// src/processors/browser-processor.ts
|
|
340
173
|
import { getDebugName, safariCheck } from "@dxos/util";
|
|
@@ -443,6 +276,16 @@ var TEST_BROWSER_PROCESSOR = (config, entry) => {
|
|
|
443
276
|
};
|
|
444
277
|
var BROWSER_PROCESSOR = CONFIG.useTestProcessor ? TEST_BROWSER_PROCESSOR : APP_BROWSER_PROCESSOR;
|
|
445
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
|
+
|
|
446
289
|
// src/processors/file-processor.ts
|
|
447
290
|
import { appendFileSync, mkdirSync, openSync } from "node:fs";
|
|
448
291
|
import { dirname } from "node:path";
|
|
@@ -514,14 +357,15 @@ var FILE_PROCESSOR = createFileProcessor({
|
|
|
514
357
|
|
|
515
358
|
// src/options.ts
|
|
516
359
|
var processors = {
|
|
517
|
-
[LogProcessorType.CONSOLE]: CONSOLE_PROCESSOR,
|
|
360
|
+
[LogProcessorType.CONSOLE]: processors_exports.CONSOLE_PROCESSOR,
|
|
518
361
|
[LogProcessorType.BROWSER]: BROWSER_PROCESSOR,
|
|
519
362
|
[LogProcessorType.DEBUG]: DEBUG_PROCESSOR
|
|
520
363
|
};
|
|
521
|
-
var
|
|
364
|
+
var browser = (typeof window !== "undefined" || typeof navigator !== "undefined") && !(typeof process !== "undefined" && process?.env?.VITEST);
|
|
522
365
|
var DEFAULT_PROCESSORS = [
|
|
523
|
-
|
|
366
|
+
browser ? BROWSER_PROCESSOR : processors_exports.CONSOLE_PROCESSOR
|
|
524
367
|
];
|
|
368
|
+
var parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
525
369
|
var parseFilter = (filter) => {
|
|
526
370
|
if (typeof filter === "number") {
|
|
527
371
|
return [
|
|
@@ -530,7 +374,6 @@ var parseFilter = (filter) => {
|
|
|
530
374
|
}
|
|
531
375
|
];
|
|
532
376
|
}
|
|
533
|
-
const parseLogLevel = (level, defValue = LogLevel.WARN) => levels[level.toLowerCase()] ?? defValue;
|
|
534
377
|
const lines = typeof filter === "string" ? filter.split(/,\s*/) : filter;
|
|
535
378
|
return lines.map((filter2) => {
|
|
536
379
|
const [pattern, level] = filter2.split(":");
|
|
@@ -542,54 +385,37 @@ var parseFilter = (filter) => {
|
|
|
542
385
|
};
|
|
543
386
|
});
|
|
544
387
|
};
|
|
545
|
-
var
|
|
546
|
-
const
|
|
388
|
+
var createConfig = (options) => {
|
|
389
|
+
const envOptions = "process" in globalThis ? {
|
|
547
390
|
file: process.env.LOG_CONFIG,
|
|
548
391
|
filter: process.env.LOG_FILTER,
|
|
549
392
|
processor: process.env.LOG_PROCESSOR
|
|
550
393
|
} : void 0;
|
|
551
|
-
const mergedOptions = defaultsDeep({}, loadOptions(
|
|
394
|
+
const mergedOptions = defaultsDeep({}, (0, platform_exports.loadOptions)(envOptions?.file), envOptions, options);
|
|
552
395
|
return {
|
|
553
396
|
options: mergedOptions,
|
|
554
397
|
filters: parseFilter(mergedOptions.filter ?? LogLevel.INFO),
|
|
555
398
|
captureFilters: parseFilter(mergedOptions.captureFilter ?? LogLevel.WARN),
|
|
556
399
|
processors: mergedOptions.processor ? [
|
|
557
400
|
processors[mergedOptions.processor]
|
|
558
|
-
] :
|
|
401
|
+
] : [
|
|
402
|
+
...DEFAULT_PROCESSORS
|
|
403
|
+
],
|
|
559
404
|
prefix: mergedOptions.prefix
|
|
560
405
|
};
|
|
561
406
|
};
|
|
562
407
|
|
|
563
408
|
// src/log.ts
|
|
409
|
+
var logCount = 0;
|
|
564
410
|
var createLog = () => {
|
|
565
411
|
const log2 = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
566
|
-
log2
|
|
412
|
+
Object.assign(log2, {
|
|
413
|
+
_id: `log-${++logCount}`,
|
|
414
|
+
_config: createConfig()
|
|
415
|
+
});
|
|
567
416
|
Object.defineProperty(log2, "runtimeConfig", {
|
|
568
417
|
get: () => log2._config
|
|
569
418
|
});
|
|
570
|
-
log2.addProcessor = (processor) => {
|
|
571
|
-
if (DEFAULT_PROCESSORS.filter((p) => p === processor).length === 0) {
|
|
572
|
-
DEFAULT_PROCESSORS.push(processor);
|
|
573
|
-
}
|
|
574
|
-
if (log2._config.processors.filter((p) => p === processor).length === 0) {
|
|
575
|
-
log2._config.processors.push(processor);
|
|
576
|
-
}
|
|
577
|
-
};
|
|
578
|
-
log2.config = (options) => {
|
|
579
|
-
log2._config = getConfig(options);
|
|
580
|
-
};
|
|
581
|
-
log2.trace = (...params) => processLog(LogLevel.TRACE, ...params);
|
|
582
|
-
log2.debug = (...params) => processLog(LogLevel.DEBUG, ...params);
|
|
583
|
-
log2.verbose = (...params) => processLog(LogLevel.VERBOSE, ...params);
|
|
584
|
-
log2.info = (...params) => processLog(LogLevel.INFO, ...params);
|
|
585
|
-
log2.warn = (...params) => processLog(LogLevel.WARN, ...params);
|
|
586
|
-
log2.error = (...params) => processLog(LogLevel.ERROR, ...params);
|
|
587
|
-
log2.catch = (error, context, meta) => processLog(LogLevel.ERROR, void 0, context, meta, error);
|
|
588
|
-
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");
|
|
589
|
-
log2.stack = (message, context, meta) => processLog(LogLevel.INFO, `${message ?? "Stack Dump"}
|
|
590
|
-
${getFormattedStackTrace()}`, context, meta);
|
|
591
|
-
log2.method = createMethodLogDecorator(log2);
|
|
592
|
-
log2.func = createFunctionLogDecorator(log2);
|
|
593
419
|
const processLog = (level, message, context = {}, meta, error) => {
|
|
594
420
|
log2._config.processors.forEach((processor) => processor(log2._config, {
|
|
595
421
|
level,
|
|
@@ -599,9 +425,50 @@ ${getFormattedStackTrace()}`, context, meta);
|
|
|
599
425
|
error
|
|
600
426
|
}));
|
|
601
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
|
+
});
|
|
602
469
|
return log2;
|
|
603
470
|
};
|
|
604
|
-
var log = globalThis.
|
|
471
|
+
var log = globalThis.DX_LOG ??= createLog();
|
|
605
472
|
var start = Date.now();
|
|
606
473
|
var last = start;
|
|
607
474
|
var debug = (label, args) => {
|
|
@@ -618,8 +485,11 @@ var debug = (label, args) => {
|
|
|
618
485
|
};
|
|
619
486
|
var getFormattedStackTrace = () => new Error().stack.split("\n").slice(3).join("\n");
|
|
620
487
|
|
|
488
|
+
// src/index.ts
|
|
489
|
+
__reExport(index_exports, processors_exports);
|
|
490
|
+
|
|
621
491
|
// src/experimental/ownership.ts
|
|
622
|
-
import { inspect as
|
|
492
|
+
import { inspect as inspect3 } from "node:util";
|
|
623
493
|
var kOwnershipScope = Symbol("kOwnershipScope");
|
|
624
494
|
var kCurrentOwnershipScope = Symbol("kCurrentOwnershipScope");
|
|
625
495
|
var kDebugInfoProperties = Symbol("kDebugInfoProperties");
|
|
@@ -642,7 +512,7 @@ var OwnershipScope = class {
|
|
|
642
512
|
}
|
|
643
513
|
return info;
|
|
644
514
|
}
|
|
645
|
-
[
|
|
515
|
+
[inspect3.custom]() {
|
|
646
516
|
return {
|
|
647
517
|
className: this.constr.name,
|
|
648
518
|
info: this.getInfo(),
|
|
@@ -653,14 +523,12 @@ var OwnershipScope = class {
|
|
|
653
523
|
var getCurrentOwnershipScope = (thisRef) => thisRef;
|
|
654
524
|
export {
|
|
655
525
|
BROWSER_PROCESSOR,
|
|
656
|
-
CONSOLE_PROCESSOR,
|
|
657
526
|
DEBUG_PROCESSOR,
|
|
658
|
-
DEFAULT_FORMATTER,
|
|
659
527
|
FILE_PROCESSOR,
|
|
660
528
|
LogLevel,
|
|
661
529
|
LogProcessorType,
|
|
662
|
-
SHORT_FORMATTER,
|
|
663
530
|
createFileProcessor,
|
|
531
|
+
createLog,
|
|
664
532
|
debug,
|
|
665
533
|
gatherLogInfoFromScope,
|
|
666
534
|
getContextFromEntry,
|
|
@@ -673,7 +541,6 @@ export {
|
|
|
673
541
|
parseFilter,
|
|
674
542
|
pick,
|
|
675
543
|
shortLevelName,
|
|
676
|
-
shouldLog
|
|
677
|
-
truncate
|
|
544
|
+
shouldLog
|
|
678
545
|
};
|
|
679
546
|
//# sourceMappingURL=index.mjs.map
|