standard-log 13.0.0 → 13.0.2
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/cjs/_virtual/_rolldown/runtime.js +23 -0
- package/cjs/console.d.ts +10 -7
- package/cjs/console.d.ts.map +1 -1
- package/cjs/console.js +54 -69
- package/cjs/console.js.map +1 -1
- package/cjs/errors.d.ts +9 -6
- package/cjs/errors.d.ts.map +1 -1
- package/cjs/errors.js +22 -45
- package/cjs/errors.js.map +1 -1
- package/cjs/formatter.d.ts +9 -6
- package/cjs/formatter.d.ts.map +1 -1
- package/cjs/formatter.js +42 -49
- package/cjs/formatter.js.map +1 -1
- package/cjs/index.d.ts +8 -9
- package/cjs/index.js +26 -28
- package/cjs/log_levels.d.ts +76 -73
- package/cjs/log_levels.d.ts.map +1 -1
- package/cjs/log_levels.js +104 -110
- package/cjs/log_levels.js.map +1 -1
- package/cjs/log_store.d.ts +20 -17
- package/cjs/log_store.d.ts.map +1 -1
- package/cjs/log_store.js +44 -39
- package/cjs/log_store.js.map +1 -1
- package/cjs/logger.d.ts +6 -3
- package/cjs/logger.d.ts.map +1 -1
- package/cjs/logger.js +66 -87
- package/cjs/logger.js.map +1 -1
- package/cjs/memory.d.ts +20 -17
- package/cjs/memory.d.ts.map +1 -1
- package/cjs/memory.js +55 -62
- package/cjs/memory.js.map +1 -1
- package/cjs/platform.browser.d.ts +7 -4
- package/cjs/platform.browser.d.ts.map +1 -1
- package/cjs/platform.browser.js +8 -6
- package/cjs/platform.browser.js.map +1 -1
- package/cjs/platform.d.ts +7 -4
- package/cjs/platform.d.ts.map +1 -1
- package/cjs/platform.js +9 -7
- package/cjs/platform.js.map +1 -1
- package/cjs/standard_log.ctx.d.ts +11 -8
- package/cjs/standard_log.ctx.d.ts.map +1 -1
- package/cjs/standard_log.ctx.js +6 -5
- package/cjs/standard_log.ctx.js.map +1 -1
- package/cjs/standard_log.d.ts +14 -12
- package/cjs/standard_log.d.ts.map +1 -1
- package/cjs/standard_log.js +84 -112
- package/cjs/standard_log.js.map +1 -1
- package/cjs/standard_log.testing.d.ts +16 -13
- package/cjs/standard_log.testing.d.ts.map +1 -1
- package/cjs/standard_log.testing.js +20 -35
- package/cjs/standard_log.testing.js.map +1 -1
- package/cjs/testing/index.d.ts +3 -3
- package/cjs/testing/index.js +3 -6
- package/cjs/types.d.ts +125 -124
- package/cjs/types.d.ts.map +1 -1
- package/cjs/types.js +0 -3
- package/dist/standard-log.esm.js +874 -1401
- package/dist/standard-log.esm.js.map +1 -1
- package/dist/standard-log.iife.js +952 -0
- package/dist/standard-log.iife.js.map +1 -0
- package/esm/console.d.ts +10 -7
- package/esm/console.d.ts.map +1 -1
- package/esm/console.js +54 -62
- package/esm/console.js.map +1 -1
- package/esm/errors.d.ts +9 -6
- package/esm/errors.d.ts.map +1 -1
- package/esm/errors.js +21 -21
- package/esm/errors.js.map +1 -1
- package/esm/formatter.d.ts +9 -6
- package/esm/formatter.d.ts.map +1 -1
- package/esm/formatter.js +38 -31
- package/esm/formatter.js.map +1 -1
- package/esm/index.d.ts +8 -9
- package/esm/index.js +7 -7
- package/esm/log_levels.d.ts +76 -73
- package/esm/log_levels.d.ts.map +1 -1
- package/esm/log_levels.js +102 -107
- package/esm/log_levels.js.map +1 -1
- package/esm/log_store.d.ts +20 -17
- package/esm/log_store.d.ts.map +1 -1
- package/esm/log_store.js +44 -37
- package/esm/log_store.js.map +1 -1
- package/esm/logger.d.ts +6 -3
- package/esm/logger.d.ts.map +1 -1
- package/esm/logger.js +66 -65
- package/esm/logger.js.map +1 -1
- package/esm/memory.d.ts +20 -17
- package/esm/memory.d.ts.map +1 -1
- package/esm/memory.js +55 -60
- package/esm/memory.js.map +1 -1
- package/esm/platform.browser.d.ts +7 -4
- package/esm/platform.browser.d.ts.map +1 -1
- package/esm/platform.browser.js +7 -3
- package/esm/platform.browser.js.map +1 -1
- package/esm/platform.d.ts +7 -4
- package/esm/platform.d.ts.map +1 -1
- package/esm/platform.js +8 -4
- package/esm/platform.js.map +1 -1
- package/esm/standard_log.ctx.d.ts +11 -8
- package/esm/standard_log.ctx.d.ts.map +1 -1
- package/esm/standard_log.ctx.js +6 -2
- package/esm/standard_log.ctx.js.map +1 -1
- package/esm/standard_log.d.ts +14 -12
- package/esm/standard_log.d.ts.map +1 -1
- package/esm/standard_log.js +83 -98
- package/esm/standard_log.js.map +1 -1
- package/esm/standard_log.testing.d.ts +16 -13
- package/esm/standard_log.testing.d.ts.map +1 -1
- package/esm/standard_log.testing.js +19 -20
- package/esm/standard_log.testing.js.map +1 -1
- package/esm/testing/index.d.ts +3 -3
- package/esm/testing/index.js +2 -2
- package/esm/types.d.ts +125 -124
- package/esm/types.d.ts.map +1 -1
- package/esm/types.js +0 -1
- package/package.json +8 -42
- package/cjs/index.d.ts.map +0 -1
- package/cjs/index.js.map +0 -1
- package/cjs/testing/index.d.ts.map +0 -1
- package/cjs/testing/index.js.map +0 -1
- package/cjs/types.js.map +0 -1
- package/dist/standard-log.es5.js +0 -10628
- package/dist/standard-log.es5.js.gz +0 -0
- package/dist/standard-log.es5.js.map +0 -1
- package/dist/standard-log.es5.js.map.gz +0 -0
- package/dist/standard-log.esm.js.gz +0 -0
- package/dist/standard-log.esm.js.map.gz +0 -0
- package/esm/index.d.ts.map +0 -1
- package/esm/index.js.map +0 -1
- package/esm/testing/index.d.ts.map +0 -1
- package/esm/testing/index.js.map +0 -1
- package/esm/types.js.map +0 -1
package/esm/standard_log.js
CHANGED
|
@@ -1,108 +1,93 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
if (!ctx.gsl)
|
|
14
|
-
ctx.gsl = closure;
|
|
15
|
-
return closure.standardLog;
|
|
1
|
+
import { DEFAULT_LOG_METHOD_NAMES, logLevels } from "./log_levels.js";
|
|
2
|
+
import { createLogStore } from "./log_store.js";
|
|
3
|
+
import { createLogger } from "./logger.js";
|
|
4
|
+
import { ctx } from "./standard_log.ctx.js";
|
|
5
|
+
import { record, required } from "type-plus";
|
|
6
|
+
//#region ts/standard_log.ts
|
|
7
|
+
function createStandardLog(options) {
|
|
8
|
+
const closure = createStandardLogClosure(options);
|
|
9
|
+
if (options?.reporters?.some((r) => !r.id)) closure.standardLog.getLogger("standard-log").critical(`Detected reporter with empty id. This is not allowed as it will create problems with feature like 'getNonConsoleLogger()'. Please add an id to your reporter.`);
|
|
10
|
+
if (!ctx.gsl) ctx.gsl = closure;
|
|
11
|
+
return closure.standardLog;
|
|
16
12
|
}
|
|
17
|
-
function noop() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
13
|
+
function noop() {}
|
|
14
|
+
function createStandardLogClosure(options) {
|
|
15
|
+
const store = createLogStore(required({ logLevel: logLevels.info }, options));
|
|
16
|
+
const nonConsoleReporters = options?.reporters?.filter((r) => !r.isConsoleReporter).map((r) => r.id) ?? [];
|
|
17
|
+
const logMethods = DEFAULT_LOG_METHOD_NAMES.concat(Object.keys(options?.customLevels ?? {})).concat([
|
|
18
|
+
"on",
|
|
19
|
+
"count",
|
|
20
|
+
"write"
|
|
21
|
+
]);
|
|
22
|
+
return {
|
|
23
|
+
store,
|
|
24
|
+
standardLog: {
|
|
25
|
+
get logLevel() {
|
|
26
|
+
return store.logLevel;
|
|
27
|
+
},
|
|
28
|
+
toLogLevelName(level) {
|
|
29
|
+
return store.logLevelStore.getName(level);
|
|
30
|
+
},
|
|
31
|
+
toLogLevel(name) {
|
|
32
|
+
return store.logLevelStore.getLevel(name);
|
|
33
|
+
},
|
|
34
|
+
getLogger(id, options) {
|
|
35
|
+
if (store.loggers[id]) return store.loggers[id];
|
|
36
|
+
return store.loggers[id] = createLogger(store, id, {
|
|
37
|
+
ssf: this.getLogger,
|
|
38
|
+
...options
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
getNonConsoleLogger(id, options) {
|
|
42
|
+
if (store.nonConsoleLoggers[id]) return store.nonConsoleLoggers[id];
|
|
43
|
+
if (store.loggers[id]) {
|
|
44
|
+
this.getLogger("standard-log").warn(`attempt to create a non-console logger with existing id ('${id}'), ignoring`);
|
|
45
|
+
return store.nonConsoleLoggers[id] = createDummyLogger(logMethods);
|
|
46
|
+
}
|
|
47
|
+
return store.nonConsoleLoggers[id] = nonConsoleReporters.length === 0 ? createDummyLogger(logMethods) : createLogger(store, id, {
|
|
48
|
+
ssf: this.getNonConsoleLogger,
|
|
49
|
+
...options,
|
|
50
|
+
writeTo(reporterId) {
|
|
51
|
+
return nonConsoleReporters.indexOf(reporterId) >= 0;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
66
57
|
}
|
|
67
58
|
function createDummyLogger(logMethods) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
59
|
+
return logMethods.reduce((p, m) => {
|
|
60
|
+
p[m] = noop;
|
|
61
|
+
return p;
|
|
62
|
+
}, record());
|
|
72
63
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
64
|
+
function suppressLogs(block, ...logs) {
|
|
65
|
+
const origLevels = logs.map((l) => l.level);
|
|
66
|
+
logs.forEach((l) => l.level = logLevels.none);
|
|
67
|
+
const result = block();
|
|
68
|
+
logs.forEach((l, i) => l.level = origLevels[i]);
|
|
69
|
+
return result;
|
|
79
70
|
}
|
|
80
|
-
|
|
81
|
-
|
|
71
|
+
function getLogger(id, options) {
|
|
72
|
+
return getGlobalSL().getLogger(id, options);
|
|
82
73
|
}
|
|
83
74
|
function getGlobalSL() {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return ctx.gsl.standardLog;
|
|
75
|
+
if (!ctx.gsl) ctx.gsl = createStandardLogClosure();
|
|
76
|
+
return ctx.gsl.standardLog;
|
|
87
77
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
reporters.length = 0;
|
|
100
|
-
reporters.push(...options.reporters);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
ctx.gsl = createStandardLogClosure(options);
|
|
105
|
-
}
|
|
106
|
-
ctx.configured = true;
|
|
78
|
+
function configGlobal(options) {
|
|
79
|
+
if (ctx.configured) ctx.gsl.standardLog.getLogger("standard-log").warn("configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.");
|
|
80
|
+
if (ctx.gsl) {
|
|
81
|
+
if (options.logLevel) ctx.gsl.store.logLevel = options.logLevel;
|
|
82
|
+
if (options.reporters) {
|
|
83
|
+
const reporters = ctx.gsl.store.reporters;
|
|
84
|
+
reporters.length = 0;
|
|
85
|
+
reporters.push(...options.reporters);
|
|
86
|
+
}
|
|
87
|
+
} else ctx.gsl = createStandardLogClosure(options);
|
|
88
|
+
ctx.configured = true;
|
|
107
89
|
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { configGlobal, createStandardLog, createStandardLogClosure, getLogger, suppressLogs };
|
|
92
|
+
|
|
108
93
|
//# sourceMappingURL=standard_log.js.map
|
package/esm/standard_log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard_log.js","
|
|
1
|
+
{"version":3,"file":"standard_log.js","names":[],"sources":["../ts/standard_log.ts"],"sourcesContent":["import { record, required } from 'type-plus'\nimport { DEFAULT_LOG_METHOD_NAMES, logLevels } from './log_levels.js'\nimport { createLogStore, type LogStore } from './log_store.js'\nimport { createLogger } from './logger.js'\nimport { ctx } from './standard_log.ctx.js'\nimport type {\n\tLogger,\n\tLoggerOptions,\n\tLogMethodNames,\n\tStandardLogInstance,\n\tStandardLogOptions\n} from './types.js'\n\nexport interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {}\n\nexport function createStandardLog<N extends string = LogMethodNames>(\n\toptions?: StandardLogOptions<N>\n): StandardLog<N> {\n\tconst closure = createStandardLogClosure(options)\n\tif (options?.reporters?.some(r => !r.id)) {\n\t\tconst log = closure.standardLog.getLogger('standard-log')\n\t\tlog.critical(\n\t\t\t`Detected reporter with empty id. This is not allowed as it will create problems with feature like 'getNonConsoleLogger()'. Please add an id to your reporter.`\n\t\t)\n\t}\n\n\tif (!ctx.gsl) ctx.gsl = closure as any\n\treturn closure.standardLog\n}\n\nfunction noop() {}\n\nexport function createStandardLogClosure<N extends string = LogMethodNames>(\n\toptions?: StandardLogOptions<N>\n): { store: LogStore; standardLog: StandardLog<N> } {\n\t// TODO reporter.id must not be empty\n\tconst store = createLogStore(required({ logLevel: logLevels.info }, options))\n\tconst nonConsoleReporters = options?.reporters?.filter(r => !r.isConsoleReporter).map(r => r.id) ?? []\n\tconst logMethods = DEFAULT_LOG_METHOD_NAMES.concat(Object.keys(options?.customLevels ?? {})).concat([\n\t\t'on',\n\t\t'count',\n\t\t'write'\n\t])\n\treturn {\n\t\tstore,\n\t\tstandardLog: {\n\t\t\tget logLevel() {\n\t\t\t\treturn store.logLevel\n\t\t\t},\n\n\t\t\ttoLogLevelName(level: number) {\n\t\t\t\treturn store.logLevelStore.getName(level)\n\t\t\t},\n\t\t\ttoLogLevel(name: string) {\n\t\t\t\treturn store.logLevelStore.getLevel(name)\n\t\t\t},\n\t\t\tgetLogger(id: string, options?: LoggerOptions) {\n\t\t\t\tif (store.loggers[id]) return store.loggers[id] as any\n\t\t\t\treturn (store.loggers[id] = createLogger(store, id, { ssf: this.getLogger, ...options }) as any)\n\t\t\t},\n\t\t\tgetNonConsoleLogger(id, options?) {\n\t\t\t\tif (store.nonConsoleLoggers[id]) return store.nonConsoleLoggers[id] as any\n\n\t\t\t\tif (store.loggers[id]) {\n\t\t\t\t\tconst log = this.getLogger('standard-log')\n\t\t\t\t\tlog.warn(`attempt to create a non-console logger with existing id ('${id}'), ignoring`)\n\t\t\t\t\treturn (store.nonConsoleLoggers[id] = createDummyLogger(logMethods))\n\t\t\t\t}\n\n\t\t\t\treturn (store.nonConsoleLoggers[id] =\n\t\t\t\t\tnonConsoleReporters.length === 0\n\t\t\t\t\t\t? createDummyLogger(logMethods)\n\t\t\t\t\t\t: createLogger(store, id, {\n\t\t\t\t\t\t\t\tssf: this.getNonConsoleLogger,\n\t\t\t\t\t\t\t\t...options,\n\t\t\t\t\t\t\t\twriteTo(reporterId) {\n\t\t\t\t\t\t\t\t\treturn nonConsoleReporters.indexOf(reporterId) >= 0\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}))\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction createDummyLogger(logMethods: string[]) {\n\treturn logMethods.reduce((p, m) => {\n\t\tp[m] = noop\n\t\treturn p\n\t}, record()) as Logger\n}\n\n/**\n * Suppress logging within the code block.\n */\nexport function suppressLogs<R>(block: () => R, log: Logger, ...logs: Logger[]): R\nexport function suppressLogs<R>(block: () => R, ...logs: Logger[]): R {\n\tconst origLevels = logs.map(l => l.level)\n\tlogs.forEach(l => (l.level = logLevels.none))\n\tconst result = block()\n\tlogs.forEach((l, i) => (l.level = origLevels[i]))\n\treturn result\n}\n\nexport type GetLogger<N extends string = LogMethodNames> = (\n\tid: string,\n\toptions?: LoggerOptions\n) => Logger<LogMethodNames | N>\n\nexport function getLogger<N extends string = LogMethodNames>(id: string, options?: LoggerOptions) {\n\treturn getGlobalSL<N>().getLogger(id, options)\n}\n\nfunction getGlobalSL<N extends string = LogMethodNames>(): StandardLogInstance<N> {\n\tif (!ctx.gsl) ctx.gsl = createStandardLogClosure()\n\n\treturn ctx.gsl!.standardLog as StandardLogInstance<N>\n}\n\nexport function configGlobal(options: Omit<StandardLogOptions, 'customLevels'>) {\n\tif (ctx.configured) {\n\t\tconst log = ctx.gsl!.standardLog.getLogger('standard-log')\n\t\tlog.warn(\n\t\t\t'configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.'\n\t\t)\n\t}\n\n\tif (ctx.gsl) {\n\t\tif (options.logLevel) {\n\t\t\tctx.gsl.store.logLevel = options.logLevel\n\t\t}\n\t\tif (options.reporters) {\n\t\t\tconst reporters = ctx.gsl.store.reporters\n\t\t\treporters.length = 0\n\t\t\treporters.push(...options.reporters)\n\t\t}\n\t} else {\n\t\tctx.gsl = createStandardLogClosure(options)\n\t}\n\tctx.configured = true\n}\n"],"mappings":";;;;;;AAeA,SAAgB,kBACf,SACiB;CACjB,MAAM,UAAU,yBAAyB,OAAO;CAChD,IAAI,SAAS,WAAW,MAAK,MAAK,CAAC,EAAE,EAAE,GAEtC,QADoB,YAAY,UAAU,cACxC,CAAC,CAAC,SACH,+JACD;CAGD,IAAI,CAAC,IAAI,KAAK,IAAI,MAAM;CACxB,OAAO,QAAQ;AAChB;AAEA,SAAS,OAAO,CAAC;AAEjB,SAAgB,yBACf,SACmD;CAEnD,MAAM,QAAQ,eAAe,SAAS,EAAE,UAAU,UAAU,KAAK,GAAG,OAAO,CAAC;CAC5E,MAAM,sBAAsB,SAAS,WAAW,QAAO,MAAK,CAAC,EAAE,iBAAiB,CAAC,CAAC,KAAI,MAAK,EAAE,EAAE,KAAK,CAAC;CACrG,MAAM,aAAa,yBAAyB,OAAO,OAAO,KAAK,SAAS,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO;EACnG;EACA;EACA;CACD,CAAC;CACD,OAAO;EACN;EACA,aAAa;GACZ,IAAI,WAAW;IACd,OAAO,MAAM;GACd;GAEA,eAAe,OAAe;IAC7B,OAAO,MAAM,cAAc,QAAQ,KAAK;GACzC;GACA,WAAW,MAAc;IACxB,OAAO,MAAM,cAAc,SAAS,IAAI;GACzC;GACA,UAAU,IAAY,SAAyB;IAC9C,IAAI,MAAM,QAAQ,KAAK,OAAO,MAAM,QAAQ;IAC5C,OAAQ,MAAM,QAAQ,MAAM,aAAa,OAAO,IAAI;KAAE,KAAK,KAAK;KAAW,GAAG;IAAQ,CAAC;GACxF;GACA,oBAAoB,IAAI,SAAU;IACjC,IAAI,MAAM,kBAAkB,KAAK,OAAO,MAAM,kBAAkB;IAEhE,IAAI,MAAM,QAAQ,KAAK;KAEtB,KADiB,UAAU,cACzB,CAAC,CAAC,KAAK,6DAA6D,GAAG,aAAa;KACtF,OAAQ,MAAM,kBAAkB,MAAM,kBAAkB,UAAU;IACnE;IAEA,OAAQ,MAAM,kBAAkB,MAC/B,oBAAoB,WAAW,IAC5B,kBAAkB,UAAU,IAC5B,aAAa,OAAO,IAAI;KACxB,KAAK,KAAK;KACV,GAAG;KACH,QAAQ,YAAY;MACnB,OAAO,oBAAoB,QAAQ,UAAU,KAAK;KACnD;IACD,CAAC;GACL;EACD;CACD;AACD;AAEA,SAAS,kBAAkB,YAAsB;CAChD,OAAO,WAAW,QAAQ,GAAG,MAAM;EAClC,EAAE,KAAK;EACP,OAAO;CACR,GAAG,OAAO,CAAC;AACZ;AAMA,SAAgB,aAAgB,OAAgB,GAAG,MAAmB;CACrE,MAAM,aAAa,KAAK,KAAI,MAAK,EAAE,KAAK;CACxC,KAAK,SAAQ,MAAM,EAAE,QAAQ,UAAU,IAAK;CAC5C,MAAM,SAAS,MAAM;CACrB,KAAK,SAAS,GAAG,MAAO,EAAE,QAAQ,WAAW,EAAG;CAChD,OAAO;AACR;AAOA,SAAgB,UAA6C,IAAY,SAAyB;CACjG,OAAO,YAAe,CAAC,CAAC,UAAU,IAAI,OAAO;AAC9C;AAEA,SAAS,cAAyE;CACjF,IAAI,CAAC,IAAI,KAAK,IAAI,MAAM,yBAAyB;CAEjD,OAAO,IAAI,IAAK;AACjB;AAEA,SAAgB,aAAa,SAAmD;CAC/E,IAAI,IAAI,YAEP,IADgB,IAAK,YAAY,UAAU,cACzC,CAAC,CAAC,KACH,kJACD;CAGD,IAAI,IAAI,KAAK;EACZ,IAAI,QAAQ,UACX,IAAI,IAAI,MAAM,WAAW,QAAQ;EAElC,IAAI,QAAQ,WAAW;GACtB,MAAM,YAAY,IAAI,IAAI,MAAM;GAChC,UAAU,SAAS;GACnB,UAAU,KAAK,GAAG,QAAQ,SAAS;EACpC;CACD,OACC,IAAI,MAAM,yBAAyB,OAAO;CAE3C,IAAI,aAAa;AAClB"}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { LogMethodNames, StandardLogOptions } from "./types.js";
|
|
2
|
+
import { MemoryLogReporter } from "./memory.js";
|
|
3
|
+
import { StandardLog } from "./standard_log.js";
|
|
4
|
+
//#region ts/standard_log.testing.d.ts
|
|
5
|
+
type StandardLogForTestOptions<N extends string = LogMethodNames> = StandardLogOptions<N> & {
|
|
6
|
+
/**
|
|
7
|
+
* Send the logs to console for easy debugging.
|
|
8
|
+
*
|
|
9
|
+
* @default false
|
|
10
|
+
*/
|
|
11
|
+
emitLog?: boolean;
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {
|
|
14
|
+
reporter: MemoryLogReporter;
|
|
14
15
|
};
|
|
15
|
-
|
|
16
|
+
declare function createStandardLogForTest<N extends string = LogMethodNames>(options?: StandardLogForTestOptions<N>): StandardLogForTest<N>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { StandardLogForTest, StandardLogForTestOptions, createStandardLogForTest };
|
|
16
19
|
//# sourceMappingURL=standard_log.testing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard_log.testing.d.ts","
|
|
1
|
+
{"version":3,"file":"standard_log.testing.d.ts","names":[],"sources":["../ts/standard_log.testing.ts"],"mappings":";;;;KAMY,0BAA0B,mBAAmB,kBAAkB,mBAAmB;;;;;;EAM7F;;KAGW,mBAAmB,mBAAmB,kBAAkB,YAAY;EAC/E,UAAU;;iBAGK,yBAAyB,mBAAmB,gBAC3D,UAAS,0BAA0B,KACjC,mBAAmB"}
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { createMemoryLogReporter } from
|
|
4
|
-
import { createStandardLogClosure } from
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
options.reporters.push(reporter);
|
|
18
|
-
}
|
|
19
|
-
const closure = createStandardLogClosure(options);
|
|
20
|
-
return { ...closure.standardLog, reporter };
|
|
1
|
+
import { logLevels } from "./log_levels.js";
|
|
2
|
+
import { createConsoleLogReporter } from "./console.js";
|
|
3
|
+
import { createMemoryLogReporter } from "./memory.js";
|
|
4
|
+
import { createStandardLogClosure } from "./standard_log.js";
|
|
5
|
+
//#region ts/standard_log.testing.ts
|
|
6
|
+
function createStandardLogForTest(options = {}) {
|
|
7
|
+
options.logLevel = options.logLevel ?? logLevels.debug;
|
|
8
|
+
options.reporters = options.reporters ?? [];
|
|
9
|
+
if (options.emitLog && !options.reporters.some((r) => r.isConsoleReporter)) options.reporters.push(createConsoleLogReporter());
|
|
10
|
+
const existingReporter = options.reporters.find((r) => r.id === "memory");
|
|
11
|
+
const reporter = existingReporter ?? createMemoryLogReporter();
|
|
12
|
+
if (!existingReporter) options.reporters.push(reporter);
|
|
13
|
+
return {
|
|
14
|
+
...createStandardLogClosure(options).standardLog,
|
|
15
|
+
reporter
|
|
16
|
+
};
|
|
21
17
|
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { createStandardLogForTest };
|
|
20
|
+
|
|
22
21
|
//# sourceMappingURL=standard_log.testing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard_log.testing.js","
|
|
1
|
+
{"version":3,"file":"standard_log.testing.js","names":[],"sources":["../ts/standard_log.testing.ts"],"sourcesContent":["import { createConsoleLogReporter } from './console.js'\nimport { logLevels } from './log_levels.js'\nimport { createMemoryLogReporter, type MemoryLogReporter } from './memory.js'\nimport { createStandardLogClosure, type StandardLog } from './standard_log.js'\nimport type { LogMethodNames, StandardLogOptions } from './types.js'\n\nexport type StandardLogForTestOptions<N extends string = LogMethodNames> = StandardLogOptions<N> & {\n\t/**\n\t * Send the logs to console for easy debugging.\n\t *\n\t * @default false\n\t */\n\temitLog?: boolean\n}\n\nexport type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & {\n\treporter: MemoryLogReporter\n}\n\nexport function createStandardLogForTest<N extends string = LogMethodNames>(\n\toptions: StandardLogForTestOptions<N> = {}\n): StandardLogForTest<N> {\n\toptions.logLevel = options.logLevel ?? logLevels.debug\n\toptions.reporters = options.reporters ?? []\n\n\tif (options.emitLog && !options.reporters.some(r => r.isConsoleReporter)) {\n\t\t// this is used for debugging,\n\t\t// so no need to use color reporter.\n\t\toptions.reporters.push(createConsoleLogReporter())\n\t}\n\n\tconst existingReporter = options.reporters.find(r => r.id === 'memory') as MemoryLogReporter\n\tconst reporter = existingReporter ?? createMemoryLogReporter()\n\tif (!existingReporter) {\n\t\toptions.reporters.push(reporter)\n\t}\n\tconst closure = createStandardLogClosure<N>(options)\n\treturn { ...closure.standardLog, reporter }\n}\n"],"mappings":";;;;;AAmBA,SAAgB,yBACf,UAAwC,CAAC,GACjB;CACxB,QAAQ,WAAW,QAAQ,YAAY,UAAU;CACjD,QAAQ,YAAY,QAAQ,aAAa,CAAC;CAE1C,IAAI,QAAQ,WAAW,CAAC,QAAQ,UAAU,MAAK,MAAK,EAAE,iBAAiB,GAGtE,QAAQ,UAAU,KAAK,yBAAyB,CAAC;CAGlD,MAAM,mBAAmB,QAAQ,UAAU,MAAK,MAAK,EAAE,OAAO,QAAQ;CACtE,MAAM,WAAW,oBAAoB,wBAAwB;CAC7D,IAAI,CAAC,kBACJ,QAAQ,UAAU,KAAK,QAAQ;CAGhC,OAAO;EAAE,GADO,yBAA4B,OAC1B,CAAC,CAAC;EAAa;CAAS;AAC3C"}
|
package/esm/testing/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { MemoryLogReporter } from "../memory.js";
|
|
2
|
+
import { StandardLogForTest, StandardLogForTestOptions, createStandardLogForTest } from "../standard_log.testing.js";
|
|
3
|
+
export { type MemoryLogReporter, type StandardLogForTest, type StandardLogForTestOptions, createStandardLogForTest };
|
package/esm/testing/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { createStandardLogForTest } from "../standard_log.testing.js";
|
|
2
|
+
export { createStandardLogForTest };
|
package/esm/types.d.ts
CHANGED
|
@@ -1,144 +1,145 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { StackTraceMeta } from "@just-func/types";
|
|
2
|
+
//#region ts/types.d.ts
|
|
3
|
+
type StandardLogOptions<CustomLevelNames extends string = LogMethodNames> = {
|
|
4
|
+
/**
|
|
5
|
+
* A map of custom log levels.
|
|
6
|
+
*
|
|
7
|
+
* Each logger created will have a method for each custom level.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { createStandardLog } from 'standard-log'
|
|
11
|
+
*
|
|
12
|
+
* const sl = createStandardLog({ customLevels: { foo: 100 } })
|
|
13
|
+
* const logger = sl.getLogger('my-logger')
|
|
14
|
+
*
|
|
15
|
+
* logger.foo('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (FOO) Hello world!
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
customLevels?: Record<CustomLevelNames, number>;
|
|
19
|
+
logLevel?: number;
|
|
20
|
+
reporters?: LogReporter[];
|
|
20
21
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
interface LoggerOptions extends StackTraceMeta {
|
|
23
|
+
level?: number;
|
|
24
|
+
writeTo?: LogReporter | ReporterFilter;
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
} & {
|
|
42
|
-
[k in N]: LogMethod;
|
|
43
|
-
};
|
|
26
|
+
type Logger<N extends string = LogMethodNames> = {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
/**
|
|
29
|
+
* Logger local log level.
|
|
30
|
+
*/
|
|
31
|
+
level?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Logs with an increment counter.
|
|
34
|
+
* This is useful during debugging to check for steps executed.
|
|
35
|
+
*/
|
|
36
|
+
count(...args: any[]): void;
|
|
37
|
+
on(level: number | N, logFunction: LogFunction): void;
|
|
38
|
+
/**
|
|
39
|
+
* Write custom log entries.
|
|
40
|
+
*/
|
|
41
|
+
write(entry: LogEntry): void;
|
|
42
|
+
} & { [k in N]: LogMethod; };
|
|
44
43
|
/**
|
|
45
44
|
* Names of the standard log methods.
|
|
46
45
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
type LogMethodNames = 'emergency' | 'alert' | 'critical' | 'error' | 'warn' | 'notice' | 'info' | 'debug' | 'trace' | 'planck';
|
|
47
|
+
type LogEntry = {
|
|
48
|
+
id: string;
|
|
49
|
+
level: number;
|
|
50
|
+
args: any[];
|
|
51
|
+
timestamp: Date;
|
|
53
52
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
53
|
+
type LogMethod = (...args: any[]) => void;
|
|
54
|
+
type LogFunction = (log: LogMethod, logLevel: number) => string | undefined | void;
|
|
55
|
+
type ReporterFilter = string | RegExp | ((reporterId: string) => boolean);
|
|
56
|
+
interface StandardLogInstance<N extends string = LogMethodNames> {
|
|
57
|
+
/**
|
|
58
|
+
* The current log level.
|
|
59
|
+
*/
|
|
60
|
+
logLevel: number;
|
|
61
|
+
/**
|
|
62
|
+
* Convert log level number to log level name.
|
|
63
|
+
*/
|
|
64
|
+
toLogLevelName(level: number): string;
|
|
65
|
+
/**
|
|
66
|
+
* Convert log level name to log level number.
|
|
67
|
+
*/
|
|
68
|
+
toLogLevel(name: N): number;
|
|
69
|
+
/**
|
|
70
|
+
* Get a logger instance with the specified id.
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* const logger = getLogger('my-logger')
|
|
74
|
+
*
|
|
75
|
+
* logger.info('Hello world!') // 2020-01-01T00:00:00.000Z my-logger (INFO) Hello world!
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
|
|
79
|
+
/**
|
|
80
|
+
* Get a non-console logger instance with the specified id.
|
|
81
|
+
*
|
|
82
|
+
* The resulting logger will only send to the reporters that are not console reporters.
|
|
83
|
+
*
|
|
84
|
+
* ```ts
|
|
85
|
+
* const logger = getNonConsoleLogger('my-logger')
|
|
86
|
+
*
|
|
87
|
+
* logger.info('Hello world!') // will not send to any console reporter
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
|
|
92
91
|
}
|
|
93
92
|
/**
|
|
94
93
|
* Formats a log entry.
|
|
95
94
|
* Depends on the reporter, it can expect a different return type.
|
|
96
95
|
* By default the return type is `any[]` which the `console` accepts.
|
|
97
96
|
*/
|
|
98
|
-
|
|
97
|
+
type LogFormatter<T = any[]> = (entry: LogEntry) => T;
|
|
99
98
|
/**
|
|
100
99
|
* Determines whether the entry should be written.
|
|
101
100
|
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
type LogFilter = (entry: LogEntry) => boolean;
|
|
102
|
+
type LogLevelEntry = {
|
|
103
|
+
name: string;
|
|
104
|
+
level: number;
|
|
106
105
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
106
|
+
interface LogReporter<T = any> {
|
|
107
|
+
readonly id: string;
|
|
108
|
+
/**
|
|
109
|
+
* Specifies the formatter to be used by the reporter.
|
|
110
|
+
* Using this you can customize how the reporter writes the log entry.
|
|
111
|
+
*/
|
|
112
|
+
readonly formatter: LogFormatter<T>;
|
|
113
|
+
/**
|
|
114
|
+
* Specifies a filter to determine should the log be written.
|
|
115
|
+
*/
|
|
116
|
+
readonly filter?: LogFilter;
|
|
117
|
+
/**
|
|
118
|
+
* Indicates if this is a console reporter.
|
|
119
|
+
* There is only one console reporter can be present in the system.
|
|
120
|
+
*/
|
|
121
|
+
readonly isConsoleReporter?: boolean;
|
|
122
|
+
write(entry: LogEntry): void;
|
|
124
123
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
124
|
+
type LogReporterOptions<T = any> = {
|
|
125
|
+
id?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Specifies the formatter to be used by the reporter.
|
|
128
|
+
* Using this you can customize how the reporter writes the log entry.
|
|
129
|
+
*/
|
|
130
|
+
formatter?: LogFormatter<T>;
|
|
131
|
+
/**
|
|
132
|
+
* Specifies a filter to determine should the log be written.
|
|
133
|
+
*/
|
|
134
|
+
filter?: LogFilter;
|
|
136
135
|
};
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
136
|
+
type LogLevel = number;
|
|
137
|
+
interface ConsoleLike {
|
|
138
|
+
debug(...args: any[]): void;
|
|
139
|
+
info(...args: any[]): void;
|
|
140
|
+
warn(...args: any[]): void;
|
|
141
|
+
error(...args: any[]): void;
|
|
143
142
|
}
|
|
143
|
+
//#endregion
|
|
144
|
+
export { ConsoleLike, LogEntry, LogFilter, LogFormatter, LogFunction, LogLevel, LogLevelEntry, LogMethod, LogMethodNames, LogReporter, LogReporterOptions, Logger, LoggerOptions, ReporterFilter, StandardLogInstance, StandardLogOptions };
|
|
144
145
|
//# sourceMappingURL=types.d.ts.map
|