standard-log 11.0.0 → 11.1.0
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/logLevels.d.ts +30 -10
- package/cjs/logLevels.d.ts.map +1 -1
- package/cjs/logLevels.js +20 -0
- package/cjs/logLevels.js.map +1 -1
- package/cjs/logStore.d.ts +1 -0
- package/cjs/logStore.d.ts.map +1 -1
- package/cjs/logStore.js +3 -2
- package/cjs/logStore.js.map +1 -1
- package/cjs/memory.d.ts +1 -0
- package/cjs/memory.d.ts.map +1 -1
- package/cjs/memory.js +13 -4
- package/cjs/memory.js.map +1 -1
- package/cjs/platform.browser.d.ts.map +1 -1
- package/cjs/platform.browser.js +2 -1
- package/cjs/platform.browser.js.map +1 -1
- package/cjs/platform.d.ts.map +1 -1
- package/cjs/platform.js +2 -1
- package/cjs/platform.js.map +1 -1
- package/cjs/standardLog.d.ts +1 -0
- package/cjs/standardLog.d.ts.map +1 -1
- package/cjs/standardLog.js +37 -6
- package/cjs/standardLog.js.map +1 -1
- package/cjs/standardLog.spec.js +58 -1
- package/cjs/standardLog.spec.js.map +1 -1
- package/dist/standard-log.es5.js +76 -14
- package/dist/standard-log.es5.js.gz +0 -0
- package/dist/standard-log.es5.js.map +1 -1
- package/dist/standard-log.es5.js.map.gz +0 -0
- package/dist/standard-log.esm.js +94 -26
- package/dist/standard-log.esm.js.gz +0 -0
- package/dist/standard-log.esm.js.map +1 -1
- package/dist/standard-log.esm.js.map.gz +0 -0
- package/esm/logLevels.d.ts +30 -10
- package/esm/logLevels.d.ts.map +1 -1
- package/esm/logLevels.js +20 -0
- package/esm/logLevels.js.map +1 -1
- package/esm/logStore.d.ts +1 -0
- package/esm/logStore.d.ts.map +1 -1
- package/esm/logStore.js +4 -3
- package/esm/logStore.js.map +1 -1
- package/esm/memory.d.ts +1 -0
- package/esm/memory.d.ts.map +1 -1
- package/esm/memory.js +11 -3
- package/esm/memory.js.map +1 -1
- package/esm/platform.browser.d.ts.map +1 -1
- package/esm/platform.browser.js +2 -1
- package/esm/platform.browser.js.map +1 -1
- package/esm/platform.d.ts.map +1 -1
- package/esm/platform.js +2 -1
- package/esm/platform.js.map +1 -1
- package/esm/standardLog.d.ts +1 -0
- package/esm/standardLog.d.ts.map +1 -1
- package/esm/standardLog.js +42 -7
- package/esm/standardLog.js.map +1 -1
- package/esm/standardLog.spec.js +59 -2
- package/esm/standardLog.spec.js.map +1 -1
- package/package.json +1 -1
- package/ts/logLevels.ts +30 -10
- package/ts/logStore.ts +5 -3
- package/ts/memory.ts +14 -3
- package/ts/platform.browser.ts +2 -1
- package/ts/platform.ts +2 -1
- package/ts/standardLog.ts +46 -8
package/esm/logLevels.d.ts
CHANGED
|
@@ -2,46 +2,66 @@ export declare const logLevels: {
|
|
|
2
2
|
/**
|
|
3
3
|
* none: 0
|
|
4
4
|
*/
|
|
5
|
-
none:
|
|
5
|
+
none: 0;
|
|
6
6
|
/**
|
|
7
7
|
* emergency: 100
|
|
8
|
+
*
|
|
9
|
+
* emergency -> alert
|
|
8
10
|
*/
|
|
9
|
-
emergency:
|
|
11
|
+
emergency: 100;
|
|
10
12
|
/**
|
|
11
13
|
* alert: 200
|
|
14
|
+
*
|
|
15
|
+
* emergency -> alert -> critical
|
|
12
16
|
*/
|
|
13
|
-
alert:
|
|
17
|
+
alert: 200;
|
|
14
18
|
/**
|
|
15
19
|
* critical: 300
|
|
20
|
+
*
|
|
21
|
+
* alert -> critical -> error
|
|
16
22
|
*/
|
|
17
|
-
critical:
|
|
23
|
+
critical: 300;
|
|
18
24
|
/**
|
|
19
25
|
* error: 400
|
|
26
|
+
*
|
|
27
|
+
* critical -> error -> warn
|
|
20
28
|
*/
|
|
21
|
-
error:
|
|
29
|
+
error: 400;
|
|
22
30
|
/**
|
|
23
31
|
* warn: 500
|
|
32
|
+
*
|
|
33
|
+
* error -> warn -> notice
|
|
24
34
|
*/
|
|
25
|
-
warn:
|
|
35
|
+
warn: 500;
|
|
26
36
|
/**
|
|
27
37
|
* notice: 600
|
|
38
|
+
*
|
|
39
|
+
* warn -> notice -> info
|
|
28
40
|
*/
|
|
29
|
-
notice:
|
|
41
|
+
notice: 600;
|
|
30
42
|
/**
|
|
31
43
|
* info: 700
|
|
44
|
+
*
|
|
45
|
+
* notice -> info -> debug
|
|
32
46
|
*/
|
|
33
|
-
info:
|
|
47
|
+
info: 700;
|
|
34
48
|
/**
|
|
35
49
|
* debug: 800
|
|
50
|
+
*
|
|
51
|
+
* info -> debug -> trace
|
|
36
52
|
*/
|
|
37
|
-
debug:
|
|
53
|
+
debug: 800;
|
|
38
54
|
/**
|
|
39
55
|
* trace: 900
|
|
56
|
+
*
|
|
57
|
+
* debug -> trace -> planck
|
|
40
58
|
*/
|
|
41
|
-
trace:
|
|
59
|
+
trace: 900;
|
|
42
60
|
/**
|
|
43
61
|
* planck: Infinity
|
|
44
62
|
* `planck unit` is a very small unit <https://en.wikipedia.org/wiki/Planck_units>.
|
|
63
|
+
*
|
|
64
|
+
* trace -> planck
|
|
45
65
|
*/
|
|
46
66
|
planck: number;
|
|
47
67
|
/**
|
package/esm/logLevels.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logLevels.d.ts","sourceRoot":"","sources":["../ts/logLevels.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,SAAS;IACpB;;OAEG;;IAEH;;
|
|
1
|
+
{"version":3,"file":"logLevels.d.ts","sourceRoot":"","sources":["../ts/logLevels.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,SAAS;IACpB;;OAEG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;OAIG;;IAEH;;;;;OAKG;;IAEH;;OAEG;;CAEJ,CAAA;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,4GAW3C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,OAEtC;AAED,eAAO,MAAM,wBAAwB,EAAE,MAAM,EAW5C,CAAA"}
|
package/esm/logLevels.js
CHANGED
|
@@ -5,43 +5,63 @@ export const logLevels = {
|
|
|
5
5
|
none: 0,
|
|
6
6
|
/**
|
|
7
7
|
* emergency: 100
|
|
8
|
+
*
|
|
9
|
+
* emergency -> alert
|
|
8
10
|
*/
|
|
9
11
|
emergency: 100,
|
|
10
12
|
/**
|
|
11
13
|
* alert: 200
|
|
14
|
+
*
|
|
15
|
+
* emergency -> alert -> critical
|
|
12
16
|
*/
|
|
13
17
|
alert: 200,
|
|
14
18
|
/**
|
|
15
19
|
* critical: 300
|
|
20
|
+
*
|
|
21
|
+
* alert -> critical -> error
|
|
16
22
|
*/
|
|
17
23
|
critical: 300,
|
|
18
24
|
/**
|
|
19
25
|
* error: 400
|
|
26
|
+
*
|
|
27
|
+
* critical -> error -> warn
|
|
20
28
|
*/
|
|
21
29
|
error: 400,
|
|
22
30
|
/**
|
|
23
31
|
* warn: 500
|
|
32
|
+
*
|
|
33
|
+
* error -> warn -> notice
|
|
24
34
|
*/
|
|
25
35
|
warn: 500,
|
|
26
36
|
/**
|
|
27
37
|
* notice: 600
|
|
38
|
+
*
|
|
39
|
+
* warn -> notice -> info
|
|
28
40
|
*/
|
|
29
41
|
notice: 600,
|
|
30
42
|
/**
|
|
31
43
|
* info: 700
|
|
44
|
+
*
|
|
45
|
+
* notice -> info -> debug
|
|
32
46
|
*/
|
|
33
47
|
info: 700,
|
|
34
48
|
/**
|
|
35
49
|
* debug: 800
|
|
50
|
+
*
|
|
51
|
+
* info -> debug -> trace
|
|
36
52
|
*/
|
|
37
53
|
debug: 800,
|
|
38
54
|
/**
|
|
39
55
|
* trace: 900
|
|
56
|
+
*
|
|
57
|
+
* debug -> trace -> planck
|
|
40
58
|
*/
|
|
41
59
|
trace: 900,
|
|
42
60
|
/**
|
|
43
61
|
* planck: Infinity
|
|
44
62
|
* `planck unit` is a very small unit <https://en.wikipedia.org/wiki/Planck_units>.
|
|
63
|
+
*
|
|
64
|
+
* trace -> planck
|
|
45
65
|
*/
|
|
46
66
|
planck: Infinity,
|
|
47
67
|
/**
|
package/esm/logLevels.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logLevels.js","sourceRoot":"","sources":["../ts/logLevels.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"logLevels.js","sourceRoot":"","sources":["../ts/logLevels.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB;;OAEG;IACH,IAAI,EAAE,CAAU;IAChB;;;;OAIG;IACH,SAAS,EAAE,GAAY;IACvB;;;;OAIG;IACH,KAAK,EAAE,GAAY;IACnB;;;;OAIG;IACH,QAAQ,EAAE,GAAY;IACtB;;;;OAIG;IACH,KAAK,EAAE,GAAY;IACnB;;;;OAIG;IACH,IAAI,EAAE,GAAY;IAClB;;;;OAIG;IACH,MAAM,EAAE,GAAY;IACpB;;;;OAIG;IACH,IAAI,EAAE,GAAY;IAClB;;;;OAIG;IACH,KAAK,EAAE,GAAY;IACnB;;;;OAIG;IACH,KAAK,EAAE,GAAY;IACnB;;;;;OAKG;IACH,MAAM,EAAE,QAAQ;IAChB;;OAEG;IACH,GAAG,EAAE,QAAQ;CACd,CAAA;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,WAAW,CAAA;IACpC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,OAAO,CAAA;IAChC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,UAAU,CAAA;IACnC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,OAAO,CAAA;IAChC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,MAAM,CAAA;IAC/B,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,QAAQ,CAAA;IACjC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,MAAM,CAAA;IAC/B,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,OAAO,CAAA;IAChC,IAAI,KAAK,IAAI,GAAG;QAAE,OAAO,OAAO,CAAA;IAChC,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,IAAY;IACrC,OAAQ,SAAiB,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAA;AACrD,CAAC;AAED,MAAM,CAAC,MAAM,wBAAwB,GAAa;IAChD,WAAW;IACX,OAAO;IACP,UAAU;IACV,OAAO;IACP,MAAM;IACN,QAAQ;IACR,MAAM;IACN,OAAO;IACP,OAAO;IACP,QAAQ;CACT,CAAA","sourcesContent":["\nexport const logLevels = {\n /**\n * none: 0\n */\n none: 0 as const,\n /**\n * emergency: 100\n *\n * emergency -> alert\n */\n emergency: 100 as const,\n /**\n * alert: 200\n *\n * emergency -> alert -> critical\n */\n alert: 200 as const,\n /**\n * critical: 300\n *\n * alert -> critical -> error\n */\n critical: 300 as const,\n /**\n * error: 400\n *\n * critical -> error -> warn\n */\n error: 400 as const,\n /**\n * warn: 500\n *\n * error -> warn -> notice\n */\n warn: 500 as const,\n /**\n * notice: 600\n *\n * warn -> notice -> info\n */\n notice: 600 as const,\n /**\n * info: 700\n *\n * notice -> info -> debug\n */\n info: 700 as const,\n /**\n * debug: 800\n *\n * info -> debug -> trace\n */\n debug: 800 as const,\n /**\n * trace: 900\n *\n * debug -> trace -> planck\n */\n trace: 900 as const,\n /**\n * planck: Infinity\n * `planck unit` is a very small unit <https://en.wikipedia.org/wiki/Planck_units>.\n *\n * trace -> planck\n */\n planck: Infinity,\n /**\n * all: Infinity\n */\n all: Infinity\n}\n\n/**\n * Convert default log level value to log level name.\n */\nexport function toLogLevelName(level: number) {\n if (level <= 100) return 'emergency'\n if (level <= 200) return 'alert'\n if (level <= 300) return 'critical'\n if (level <= 400) return 'error'\n if (level <= 500) return 'warn'\n if (level <= 600) return 'notice'\n if (level <= 700) return 'info'\n if (level <= 800) return 'debug'\n if (level <= 900) return 'trace'\n return 'planck'\n}\n\n/**\n * Convert default log level name to log level value.\n */\nexport function toLogLevel(name: string) {\n return (logLevels as any)[name.toLocaleLowerCase()]\n}\n\nexport const DEFAULT_LOG_METHOD_NAMES: string[] = [\n 'emergency',\n 'alert',\n 'critical',\n 'error',\n 'warn',\n 'notice',\n 'info',\n 'debug',\n 'trace',\n 'planck'\n]\n"]}
|
package/esm/logStore.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Logger, LogLevel, LogMethodNames, LogReporter, StandardLogOptions
|
|
|
2
2
|
export declare function createLogStore<N extends string = LogMethodNames>(options: Required<StandardLogOptions<N>>): LogStore;
|
|
3
3
|
export interface LogStore {
|
|
4
4
|
loggers: Record<string, Logger>;
|
|
5
|
+
nonConsoleLoggers: Record<string, Logger>;
|
|
5
6
|
reporters: LogReporter[];
|
|
6
7
|
logLevel: LogLevel;
|
|
7
8
|
logLevelStore: ReturnType<typeof logLevelStore>;
|
package/esm/logStore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logStore.d.ts","sourceRoot":"","sources":["../ts/logStore.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEnG,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAAE,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,
|
|
1
|
+
{"version":3,"file":"logStore.d.ts","sourceRoot":"","sources":["../ts/logStore.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEnG,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAAE,OAAO,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAQpH;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1C,SAAS,EAAE,WAAW,EAAE,CAAC;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,aAAa,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAA;CAChD;AAED,MAAM,WAAW,oBAAoB;IACnC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACtC;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB;mBAWxC,MAAM;mBAGN,MAAM;;;;;EAWxB"}
|
package/esm/logStore.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import { mapKey, reduceByKey, reduceKey } from 'type-plus';
|
|
1
|
+
import { mapKey, record, reduceByKey, reduceKey } from 'type-plus';
|
|
2
2
|
import { createConsoleLogReporter } from './console.js';
|
|
3
3
|
import { logLevels, toLogLevel, toLogLevelName } from './logLevels.js';
|
|
4
4
|
export function createLogStore(options) {
|
|
5
5
|
return {
|
|
6
|
-
loggers:
|
|
6
|
+
loggers: record(),
|
|
7
|
+
nonConsoleLoggers: record(),
|
|
7
8
|
reporters: options.reporters || [createConsoleLogReporter()],
|
|
8
9
|
logLevel: options.logLevel,
|
|
9
10
|
logLevelStore: logLevelStore(options)
|
|
10
11
|
};
|
|
11
12
|
}
|
|
12
13
|
export function logLevelStore(options) {
|
|
13
|
-
const customLevels = options.customLevels ||
|
|
14
|
+
const customLevels = options.customLevels || record();
|
|
14
15
|
const store = {
|
|
15
16
|
customLevels,
|
|
16
17
|
customLevelsReverse: reduceByKey(customLevels, (p, k) => {
|
package/esm/logStore.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logStore.js","sourceRoot":"","sources":["../ts/logStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"logStore.js","sourceRoot":"","sources":["../ts/logStore.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAGtE,MAAM,UAAU,cAAc,CAAoC,OAAwC;IACxG,OAAO;QACL,OAAO,EAAE,MAAM,EAAE;QACjB,iBAAiB,EAAE,MAAM,EAAE;QAC3B,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC5D,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,aAAa,EAAE,aAAa,CAAC,OAAO,CAAC;KACtC,CAAA;AACH,CAAC;AAcD,MAAM,UAAU,aAAa,CAAC,OAA6B;IACzD,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,MAAM,EAAE,CAAA;IAErD,MAAM,KAAK,GAAG;QACZ,YAAY;QACZ,mBAAmB,EAAE,WAAW,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACtD,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAA;YACtB,OAAO,CAAC,CAAA;QACV,CAAC,EAAE,EAA4B,CAAC;KACjC,CAAA;IACD,OAAO;QACL,OAAO,CAAC,KAAa;;YACnB,OAAO,MAAA,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC,mCAAI,cAAc,CAAC,KAAK,CAAC,CAAA;QAClE,CAAC;QACD,QAAQ,CAAC,IAAY;;YACnB,OAAO,MAAA,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,mCAAI,UAAU,CAAC,IAAI,CAAC,CAAA;QACrD,CAAC;QACD,YAAY;YACV,OAAO,SAAS,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;gBAC3C,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,KAAK;oBAAE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;gBAEpF,OAAO,MAAM,CAAA;YACf,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;QACrF,CAAC;KACF,CAAA;AACH,CAAC","sourcesContent":["\nimport { mapKey, record, reduceByKey, reduceKey } from 'type-plus'\nimport { createConsoleLogReporter } from './console.js'\nimport { logLevels, toLogLevel, toLogLevelName } from './logLevels.js'\nimport type { Logger, LogLevel, LogMethodNames, LogReporter, StandardLogOptions } from './types.js'\n\nexport function createLogStore<N extends string = LogMethodNames>(options: Required<StandardLogOptions<N>>): LogStore {\n return {\n loggers: record(),\n nonConsoleLoggers: record(),\n reporters: options.reporters || [createConsoleLogReporter()],\n logLevel: options.logLevel,\n logLevelStore: logLevelStore(options)\n }\n}\n\nexport interface LogStore {\n loggers: Record<string, Logger>,\n nonConsoleLoggers: Record<string, Logger>,\n reporters: LogReporter[],\n logLevel: LogLevel,\n logLevelStore: ReturnType<typeof logLevelStore>\n}\n\nexport interface LogLevelStoreOptions {\n customLevels?: Record<string, number>\n}\n\nexport function logLevelStore(options: LogLevelStoreOptions) {\n const customLevels = options.customLevels || record()\n\n const store = {\n customLevels,\n customLevelsReverse: reduceByKey(customLevels, (p, k) => {\n p[customLevels[k]] = k\n return p\n }, {} as Record<number, string>)\n }\n return {\n getName(level: number) {\n return store.customLevelsReverse[level] ?? toLogLevelName(level)\n },\n getLevel(name: string) {\n return store.customLevels[name] ?? toLogLevel(name)\n },\n getAllLevels() {\n return reduceKey(logLevels, (result, name) => {\n if (name !== 'none' && name !== 'all') result.push({ name, level: logLevels[name] })\n\n return result\n }, mapKey(store.customLevels, name => ({ name, level: store.customLevels[name] })))\n }\n }\n}\n"]}
|
package/esm/memory.d.ts
CHANGED
|
@@ -14,4 +14,5 @@ export declare type MemoryLogReporter = LogReporter<LogEntry> & {
|
|
|
14
14
|
export declare type MemoryLogFormatter = LogFormatter<LogEntry>;
|
|
15
15
|
export declare function toMessageWithLevel(logs: LogEntry[]): string;
|
|
16
16
|
export declare function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter;
|
|
17
|
+
export declare function createMemoryWithConsoleLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter;
|
|
17
18
|
//# sourceMappingURL=memory.d.ts.map
|
package/esm/memory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAGzF,oBAAY,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACtD,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAC;IACxB,cAAc,IAAI,MAAM,EAAE,CAAC;IAC3B,sBAAsB,IAAI,MAAM,CAAC;IACjC,4BAA4B,IAAI,MAAM,EAAE,CAAC;IACzC,IAAI,IAAI,IAAI,CAAA;CACb,CAAA;AAED,oBAAY,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAEvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAQlD;AAED,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAGzF,oBAAY,iBAAiB,GAAG,WAAW,CAAC,QAAQ,CAAC,GAAG;IACtD,IAAI,EAAE,QAAQ,EAAE,CAAC;IACjB;;;OAGG;IACH,aAAa,IAAI,MAAM,CAAC;IACxB,cAAc,IAAI,MAAM,EAAE,CAAC;IAC3B,sBAAsB,IAAI,MAAM,CAAC;IACjC,4BAA4B,IAAI,MAAM,EAAE,CAAC;IACzC,IAAI,IAAI,IAAI,CAAA;CACb,CAAA;AAED,oBAAY,kBAAkB,GAAG,YAAY,CAAC,QAAQ,CAAC,CAAA;AAEvD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,QAAQ,EAAE,UAQlD;AAED,wBAAgB,uBAAuB,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAEjG;AAoCD,wBAAgB,kCAAkC,CAAC,OAAO,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAK5G"}
|
package/esm/memory.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { required } from 'type-plus';
|
|
1
|
+
import { required, unpartial } from 'type-plus';
|
|
2
2
|
import { toInspectLogEntry } from './platform.js';
|
|
3
3
|
import { formatLogLevel } from './formatter.js';
|
|
4
4
|
import { createConsoleLogReporter } from './console.js';
|
|
@@ -12,9 +12,12 @@ export function toMessageWithLevel(logs) {
|
|
|
12
12
|
.replace(/^\(WARN\) already configured for test, ignoring config\(\) call\n/, '');
|
|
13
13
|
}
|
|
14
14
|
export function createMemoryLogReporter(options) {
|
|
15
|
+
return Object.freeze(buildMemoryReporter(unpartial({ id: 'memory' }, options)));
|
|
16
|
+
}
|
|
17
|
+
function buildMemoryReporter(options) {
|
|
15
18
|
const { id, formatter, filter } = required({ id: 'memory', formatter: (e) => e }, options);
|
|
16
19
|
const logs = [];
|
|
17
|
-
return
|
|
20
|
+
return {
|
|
18
21
|
id,
|
|
19
22
|
get formatter() { return formatter; },
|
|
20
23
|
get filter() { return filter; },
|
|
@@ -43,6 +46,11 @@ export function createMemoryLogReporter(options) {
|
|
|
43
46
|
const reporter = createConsoleLogReporter();
|
|
44
47
|
logs.forEach(l => reporter.write(l));
|
|
45
48
|
}
|
|
46
|
-
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export function createMemoryWithConsoleLogReporter(options) {
|
|
52
|
+
return Object.freeze(Object.assign(buildMemoryReporter(unpartial({ id: 'memory-with-console' }, options)), {
|
|
53
|
+
isConsoleReporter: true
|
|
54
|
+
}));
|
|
47
55
|
}
|
|
48
56
|
//# sourceMappingURL=memory.js.map
|
package/esm/memory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../ts/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,EAAE,wBAAwB,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A;QACzC,CAAC;QACD,cAAc;YACZ,OAAO,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC;iBAC/B,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;QACnC,CAAC;QACD,4BAA4B;YAC1B,OAAO,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC;iBAC/B,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,IAAI,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;QAC/E,CAAC;QACD,sBAAsB,KAAK,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAA,CAAC,CAAC;QAC5D;;WAEG;QACH,IAAI;YACF,MAAM,QAAQ,GAAG,wBAAwB,EAAE,CAAA;YAC3C,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QACtC,CAAC;KACF,CAAA;AACH,CAAC;AAED,MAAM,UAAU,kCAAkC,CAAC,OAAsC;IACvF,OAAO,MAAM,CAAC,MAAM,CAClB,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,qBAAqB,EAAE,EAAE,OAAO,CAAC,CAAC,EAAE;QACpF,iBAAiB,EAAE,IAAI;KACxB,CAAC,CAAC,CAAA;AACP,CAAC","sourcesContent":["import { required, unpartial } from 'type-plus'\nimport { toInspectLogEntry } from './platform.js'\nimport { formatLogLevel } from './formatter.js'\nimport type { LogEntry, LogFormatter, LogReporter, LogReporterOptions } from './types.js'\nimport { createConsoleLogReporter } from './console.js'\n\nexport type MemoryLogReporter = LogReporter<LogEntry> & {\n logs: LogEntry[],\n /**\n * Gets a simple log message for testing.\n * The message only contains arguments for each log entry.\n */\n getLogMessage(): string,\n getLogMessages(): string[],\n getLogMessageWithLevel(): string,\n getLogMessagesWithIdAndLevel(): string[],\n emit(): void\n}\n\nexport type MemoryLogFormatter = LogFormatter<LogEntry>\n\nexport function toMessageWithLevel(logs: LogEntry[]) {\n return logs.map(toInspectLogEntry)\n .map(log => `${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n .join('\\n')\n // if it has more than this log,\n // we assume it is running under tests,\n // and remove this log to simplify testing.\n .replace(/^\\(WARN\\) already configured for test, ignoring config\\(\\) call\\n/, '')\n}\n\nexport function createMemoryLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {\n return Object.freeze(buildMemoryReporter(unpartial({ id: 'memory' }, options)))\n}\n\nfunction buildMemoryReporter(options?: LogReporterOptions<LogEntry>) {\n const { id, formatter, filter } = required({ id: 'memory', formatter: (e: LogEntry) => e }, options)\n const logs: LogEntry[] = []\n return {\n id,\n get formatter() { return formatter },\n get filter() { return filter },\n logs,\n write(entry: LogEntry) {\n if (filter && !filter(entry)) return\n logs.push(formatter(entry))\n },\n getLogMessage() {\n return this.getLogMessages().join('\\n')\n },\n getLogMessages() {\n return logs.map(toInspectLogEntry)\n .map(log => log.args.join(' '))\n },\n getLogMessagesWithIdAndLevel() {\n return logs.map(toInspectLogEntry)\n .map(log => `${log.id} ${formatLogLevel(log.level)} ${log.args.join(' ')}`)\n },\n getLogMessageWithLevel() { return toMessageWithLevel(logs) },\n /**\n * emit the saved log to console for easy debugging\n */\n emit() {\n const reporter = createConsoleLogReporter()\n logs.forEach(l => reporter.write(l))\n }\n }\n}\n\nexport function createMemoryWithConsoleLogReporter(options?: LogReporterOptions<LogEntry>): MemoryLogReporter {\n return Object.freeze(\n Object.assign(buildMemoryReporter(unpartial({ id: 'memory-with-console' }, options)), {\n isConsoleReporter: true\n }))\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.browser.d.ts","sourceRoot":"","sources":["../ts/platform.browser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"platform.browser.d.ts","sourceRoot":"","sources":["../ts/platform.browser.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEvD,eAAO,MAAM,iBAAiB,MAAO,QAAQ,aAAM,CAAA;AAEnD,eAAO,MAAM,QAAQ,EAAE;IAAE,OAAO,CAAC,EAAE,WAAW,CAAA;CAAa,CAAA"}
|
package/esm/platform.browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.browser.js","sourceRoot":"","sources":["../ts/platform.browser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"platform.browser.js","sourceRoot":"","sources":["../ts/platform.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAGlC,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAW,EAAE,EAAE,CAAC,CAAC,CAAA;AAEnD,MAAM,CAAC,MAAM,QAAQ,GAA8B,MAAM,EAAE,CAAA","sourcesContent":["import { record } from 'type-plus'\nimport type { ConsoleLike, LogEntry } from './types.js'\n\nexport const toInspectLogEntry = (e: LogEntry) => e\n\nexport const polyfill: { console?: ConsoleLike } = record()\n"]}
|
package/esm/platform.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../ts/platform.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../ts/platform.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEvD,eAAO,MAAM,iBAAiB,MAAO,QAAQ,aAEzC,CAAA;AAEJ,eAAO,MAAM,QAAQ,EAAE;IAAE,OAAO,CAAC,EAAE,WAAW,CAAA;CAAa,CAAA"}
|
package/esm/platform.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { record } from 'type-plus';
|
|
1
2
|
import { inspect } from 'util';
|
|
2
3
|
export const toInspectLogEntry = (e) => (e.args = e.args.map(value => typeof value === 'object' && value !== null ? inspect(value) : value),
|
|
3
4
|
e);
|
|
4
|
-
export const polyfill =
|
|
5
|
+
export const polyfill = record();
|
|
5
6
|
//# sourceMappingURL=platform.js.map
|
package/esm/platform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../ts/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAG9B,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAW,EAAE,EAAE,CAAC,CAChD,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAClG,CAAC,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,QAAQ,GAA8B,EAAE,CAAA","sourcesContent":["import { inspect } from 'util'\nimport type { ConsoleLike, LogEntry } from './types.js'\n\nexport const toInspectLogEntry = (e: LogEntry) => (\n e.args = e.args.map(value => typeof value === 'object' && value !== null ? inspect(value) : value),\n e)\n\nexport const polyfill: { console?: ConsoleLike } =
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../ts/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAG9B,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAW,EAAE,EAAE,CAAC,CAChD,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAClG,CAAC,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,QAAQ,GAA8B,MAAM,EAAE,CAAA","sourcesContent":["import { record } from 'type-plus'\nimport { inspect } from 'util'\nimport type { ConsoleLike, LogEntry } from './types.js'\n\nexport const toInspectLogEntry = (e: LogEntry) => (\n e.args = e.args.map(value => typeof value === 'object' && value !== null ? inspect(value) : value),\n e)\n\nexport const polyfill: { console?: ConsoleLike } = record()\n"]}
|
package/esm/standardLog.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface StandardLogInstance<N extends string = LogMethodNames> {
|
|
|
6
6
|
toLogLevelName(level: number): string;
|
|
7
7
|
toLogLevel(name: N): number;
|
|
8
8
|
getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
|
|
9
|
+
getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>;
|
|
9
10
|
}
|
|
10
11
|
export interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {
|
|
11
12
|
}
|
package/esm/standardLog.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standardLog.d.ts","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACxD,OAAO,EAA2B,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACxE,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAErG,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc;IACpE,QAAQ,EAAE,MAA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;AAID,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EACxE,OAAO,CAAC,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAC9B;IAAE,KAAK,EAAE,QAAQ,CAAC;IAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;CAAE,CA2ClD;AASD,oBAAY,kBAAkB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG;IAAE,QAAQ,EAAE,iBAAiB,CAAA;CAAE,CAAA;AAEpH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EACxE,QAAQ,GAAE,QAA0B,GACnC,kBAAkB,CAAC,CAAC,CAAC,CAIvB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;AASlF,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,GAAG,cAAc,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,8BAE/F;AAED,eAAO,MAAM,GAAG,EAAE;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,GAAG,CAAC,EAAE;QAAE,KAAK,EAAE,QAAQ,CAAC;QAAC,WAAW,EAAE,mBAAmB,CAAC,cAAc,CAAC,CAAA;KAAE,CAAA;CACjE,CAAA;AAQZ,wBAAgB,YAAY,CAAC,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAAE,cAAc,CAAC,QAoB7E"}
|
package/esm/standardLog.js
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import { record, required } from 'type-plus';
|
|
2
2
|
import { createLogger } from './logger.js';
|
|
3
|
-
import { logLevels } from './logLevels.js';
|
|
3
|
+
import { DEFAULT_LOG_METHOD_NAMES, logLevels } from './logLevels.js';
|
|
4
4
|
import { createLogStore } from './logStore.js';
|
|
5
5
|
import { createMemoryLogReporter } from './memory.js';
|
|
6
6
|
export function createStandardLog(options) {
|
|
7
|
+
var _a;
|
|
7
8
|
const closure = createStandardLogClosure(options);
|
|
9
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.reporters) === null || _a === void 0 ? void 0 : _a.some(r => !r.id)) {
|
|
10
|
+
const log = closure.standardLog.getLogger('standard-log');
|
|
11
|
+
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.`);
|
|
12
|
+
}
|
|
8
13
|
if (!ctx.gsl)
|
|
9
14
|
ctx.gsl = closure;
|
|
10
15
|
return closure.standardLog;
|
|
11
16
|
}
|
|
17
|
+
function noop() { }
|
|
12
18
|
export function createStandardLogClosure(options) {
|
|
19
|
+
var _a, _b, _c;
|
|
20
|
+
// TODO reporter.id must not be empty
|
|
13
21
|
const store = createLogStore(required({ logLevel: logLevels.info }, options));
|
|
22
|
+
const nonConsoleReporters = (_b = (_a = options === null || options === void 0 ? void 0 : options.reporters) === null || _a === void 0 ? void 0 : _a.filter(r => !r.isConsoleReporter).map(r => r.id)) !== null && _b !== void 0 ? _b : [];
|
|
23
|
+
const logMethods = DEFAULT_LOG_METHOD_NAMES
|
|
24
|
+
.concat(Object.keys((_c = options === null || options === void 0 ? void 0 : options.customLevels) !== null && _c !== void 0 ? _c : {}))
|
|
25
|
+
.concat(['on', 'count', 'write']);
|
|
14
26
|
return {
|
|
15
27
|
store,
|
|
16
28
|
standardLog: {
|
|
@@ -25,14 +37,38 @@ export function createStandardLogClosure(options) {
|
|
|
25
37
|
if (store.loggers[id])
|
|
26
38
|
return store.loggers[id];
|
|
27
39
|
return store.loggers[id] = createLogger(store, id, { ssf: this.getLogger, ...options });
|
|
28
|
-
}
|
|
40
|
+
},
|
|
41
|
+
getNonConsoleLogger(id, options) {
|
|
42
|
+
if (store.nonConsoleLoggers[id])
|
|
43
|
+
return store.nonConsoleLoggers[id];
|
|
44
|
+
if (store.loggers[id]) {
|
|
45
|
+
const log = this.getLogger('standard-log');
|
|
46
|
+
log.warn(`attempt to create a non-console logger with existing id ('${id}'), ignoring`);
|
|
47
|
+
return store.nonConsoleLoggers[id] = createDummyLogger(logMethods);
|
|
48
|
+
}
|
|
49
|
+
return store.nonConsoleLoggers[id] = nonConsoleReporters.length === 0
|
|
50
|
+
? createDummyLogger(logMethods)
|
|
51
|
+
: createLogger(store, id, {
|
|
52
|
+
ssf: this.getNonConsoleLogger,
|
|
53
|
+
...options,
|
|
54
|
+
writeTo(reporterId) {
|
|
55
|
+
return nonConsoleReporters.indexOf(reporterId) >= 0;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
},
|
|
29
59
|
}
|
|
30
60
|
};
|
|
31
61
|
}
|
|
62
|
+
function createDummyLogger(logMethods) {
|
|
63
|
+
return logMethods.reduce((p, m) => {
|
|
64
|
+
p[m] = noop;
|
|
65
|
+
return p;
|
|
66
|
+
}, record());
|
|
67
|
+
}
|
|
32
68
|
export function createStandardLogForTest(logLevel = logLevels.debug) {
|
|
33
69
|
const reporter = createMemoryLogReporter();
|
|
34
|
-
const
|
|
35
|
-
return { ...standardLog, reporter };
|
|
70
|
+
const closure = createStandardLogClosure({ reporters: [reporter], logLevel });
|
|
71
|
+
return { ...closure.standardLog, reporter };
|
|
36
72
|
}
|
|
37
73
|
export function suppressLogs(block, ...logs) {
|
|
38
74
|
const origLevels = logs.map(l => l.level);
|
|
@@ -51,10 +87,9 @@ function getGlobalSL() {
|
|
|
51
87
|
return ctx.gsl.standardLog;
|
|
52
88
|
}
|
|
53
89
|
export function configGlobal(options) {
|
|
54
|
-
var _a;
|
|
55
90
|
if (ctx.configured) {
|
|
56
|
-
const log =
|
|
57
|
-
log
|
|
91
|
+
const log = ctx.gsl.standardLog.getLogger('standard-log');
|
|
92
|
+
log.warn('configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.');
|
|
58
93
|
}
|
|
59
94
|
if (ctx.gsl) {
|
|
60
95
|
if (options.logLevel) {
|
package/esm/standardLog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standardLog.js","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"standardLog.js","sourceRoot":"","sources":["../ts/standardLog.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,wBAAwB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AACpE,OAAO,EAAE,cAAc,EAAY,MAAM,eAAe,CAAA;AACxD,OAAO,EAAE,uBAAuB,EAAqB,MAAM,aAAa,CAAA;AAcxE,MAAM,UAAU,iBAAiB,CAC/B,OAA+B;;IAE/B,MAAM,OAAO,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAA;IACjD,IAAI,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,0CAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE;QACxC,MAAM,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,CAAA;QACzD,GAAG,CAAC,QAAQ,CAAC,+JAA+J,CAAC,CAAA;KAC9K;IAED,IAAI,CAAC,GAAG,CAAC,GAAG;QAAE,GAAG,CAAC,GAAG,GAAG,OAAc,CAAA;IACtC,OAAO,OAAO,CAAC,WAAW,CAAA;AAC5B,CAAC;AAED,SAAS,IAAI,KAAK,CAAC;A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AA;KAC7J;IAED,IAAI,GAAG,CAAC,GAAG,EAAE;QACX,IAAI,OAAO,CAAC,QAAQ,EAAE;YACpB,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAA;SAC1C;QACD,IAAI,OAAO,CAAC,SAAS,EAAE;YACrB,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAA;YACzC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAA;YACpB,SAAS,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;SACrC;KACF;SACI;QACH,GAAG,CAAC,GAAG,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAA;KAC5C;IACD,GAAG,CAAC,UAAU,GAAG,IAAI,CAAA;AACvB,CAAC","sourcesContent":["import { record, required } from 'type-plus'\nimport { createLogger } from './logger.js'\nimport { DEFAULT_LOG_METHOD_NAMES, logLevels } from './logLevels.js'\nimport { createLogStore, LogStore } from './logStore.js'\nimport { createMemoryLogReporter, MemoryLogReporter } from './memory.js'\nimport type { Logger, LoggerOptions, LogLevel, LogMethodNames, StandardLogOptions } from './types.js'\n\nexport interface StandardLogInstance<N extends string = LogMethodNames> {\n logLevel: number,\n toLogLevelName(level: number): string,\n toLogLevel(name: N): number,\n getLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>,\n getNonConsoleLogger(id: string, options?: LoggerOptions): Logger<N | LogMethodNames>\n}\n\nexport interface StandardLog<N extends string = LogMethodNames> extends Readonly<StandardLogInstance<N>> {\n}\n\nexport function createStandardLog<N extends string = LogMethodNames>(\n options?: StandardLogOptions<N>\n): StandardLog<N> {\n const closure = createStandardLogClosure(options)\n if (options?.reporters?.some(r => !r.id)) {\n const log = closure.standardLog.getLogger('standard-log')\n 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.`)\n }\n\n if (!ctx.gsl) ctx.gsl = closure as any\n return closure.standardLog\n}\n\nfunction noop() { }\n\nexport function createStandardLogClosure<N extends string = LogMethodNames>(\n options?: StandardLogOptions<N>\n): { store: LogStore, standardLog: StandardLog<N> } {\n // TODO reporter.id must not be empty\n const store = createLogStore(required({ logLevel: logLevels.info }, options))\n const nonConsoleReporters = options?.reporters?.filter(r => !r.isConsoleReporter).map(r => r.id) ?? []\n const logMethods = DEFAULT_LOG_METHOD_NAMES\n .concat(Object.keys(options?.customLevels ?? {}))\n .concat(['on', 'count', 'write'])\n return {\n store,\n standardLog: {\n get logLevel() { return store.logLevel },\n\n toLogLevelName(level: number) {\n return store.logLevelStore.getName(level)\n },\n toLogLevel(name: string) {\n return store.logLevelStore.getLevel(name)\n },\n getLogger(id: string, options?: LoggerOptions) {\n if (store.loggers[id]) return store.loggers[id] as any\n return store.loggers[id] = createLogger(store, id, { ssf: this.getLogger, ...options }) as any\n },\n getNonConsoleLogger(id, options?) {\n if (store.nonConsoleLoggers[id]) return store.nonConsoleLoggers[id] as any\n\n if (store.loggers[id]) {\n const log = this.getLogger('standard-log')\n log.warn(`attempt to create a non-console logger with existing id ('${id}'), ignoring`)\n return store.nonConsoleLoggers[id] = createDummyLogger(logMethods)\n }\n\n return store.nonConsoleLoggers[id] = nonConsoleReporters.length === 0\n ? createDummyLogger(logMethods)\n : createLogger(store, id, {\n ssf: this.getNonConsoleLogger,\n ...options,\n writeTo(reporterId) {\n return nonConsoleReporters.indexOf(reporterId) >= 0\n }\n })\n },\n }\n }\n}\n\nfunction createDummyLogger(logMethods: string[]) {\n return logMethods.reduce((p, m) => {\n p[m] = noop\n return p\n }, record()) as Logger\n}\n\nexport type StandardLogForTest<N extends string = LogMethodNames> = StandardLog<N> & { reporter: MemoryLogReporter }\n\nexport function createStandardLogForTest<N extends string = LogMethodNames>(\n logLevel: LogLevel = logLevels.debug\n): StandardLogForTest<N> {\n const reporter = createMemoryLogReporter()\n const closure = createStandardLogClosure<N>({ reporters: [reporter], logLevel })\n return { ...closure.standardLog, reporter }\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 const origLevels = logs.map(l => l.level)\n logs.forEach(l => l.level = logLevels.none)\n const result = block()\n logs.forEach((l, i) => l.level = origLevels[i])\n return result\n}\n\nexport function getLogger<N extends string = LogMethodNames>(id: string, options?: LoggerOptions) {\n return getGlobalSL<N>().getLogger(id, options)\n}\n\nexport const ctx: {\n configured?: boolean,\n gsl?: { store: LogStore, standardLog: StandardLogInstance<LogMethodNames> }\n} = record()\n\nfunction getGlobalSL<N extends string = LogMethodNames>(): StandardLogInstance<N> {\n if (!ctx.gsl) ctx.gsl = createStandardLogClosure()\n\n return ctx.gsl!.standardLog as StandardLogInstance<N>\n}\n\nexport function configGlobal(options: Omit<StandardLogOptions, 'customLevels'>) {\n if (ctx.configured) {\n const log = ctx.gsl!.standardLog.getLogger('standard-log')\n log.warn('configGlobal() is being called more than once. Please make sure this is expected. Application should use `createStandardLog()` most of the time.')\n }\n\n if (ctx.gsl) {\n if (options.logLevel) {\n ctx.gsl.store.logLevel = options.logLevel\n }\n if (options.reporters) {\n const reporters = ctx.gsl.store.reporters\n reporters.length = 0\n reporters.push(...options.reporters)\n }\n }\n else {\n ctx.gsl = createStandardLogClosure(options)\n }\n ctx.configured = true\n}\n"]}
|
package/esm/standardLog.spec.js
CHANGED
|
@@ -2,7 +2,7 @@ import { assertron as a } from 'assertron';
|
|
|
2
2
|
import { InvalidId } from './errors.js';
|
|
3
3
|
import { createStandardLog, createStandardLogForTest, getLogger, suppressLogs } from './index.js';
|
|
4
4
|
import { logLevels, toLogLevelName } from './logLevels.js';
|
|
5
|
-
import { createMemoryLogReporter } from './memory.js';
|
|
5
|
+
import { createMemoryLogReporter, createMemoryWithConsoleLogReporter } from './memory.js';
|
|
6
6
|
import { configGlobal, ctx } from './standardLog.js';
|
|
7
7
|
import { assertSSF, wrapTest } from './testUtil.js';
|
|
8
8
|
describe('createStandardLog()', () => {
|
|
@@ -31,9 +31,18 @@ describe('createStandardLog()', () => {
|
|
|
31
31
|
const mem = createMemoryLogReporter();
|
|
32
32
|
const sl = createStandardLog({ reporters: [mem] });
|
|
33
33
|
const log = sl.getLogger('x');
|
|
34
|
-
log.
|
|
34
|
+
log.notice('abc');
|
|
35
35
|
expect(mem.logs.length).toBe(1);
|
|
36
36
|
});
|
|
37
|
+
it('all reporters must have an id', () => {
|
|
38
|
+
const reporter = createMemoryLogReporter({ id: '' });
|
|
39
|
+
createStandardLog({ reporters: [reporter] });
|
|
40
|
+
a.satisfies(reporter.logs, [{
|
|
41
|
+
id: 'standard-log',
|
|
42
|
+
level: logLevels.critical,
|
|
43
|
+
args: [`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.`]
|
|
44
|
+
}]);
|
|
45
|
+
});
|
|
37
46
|
});
|
|
38
47
|
describe('related to global', () => {
|
|
39
48
|
beforeEach(() => {
|
|
@@ -516,4 +525,52 @@ describe('configGlobal()', () => {
|
|
|
516
525
|
expect(reporters).toEqual([mem]);
|
|
517
526
|
});
|
|
518
527
|
});
|
|
528
|
+
describe('getNonConsoleLogger()', () => {
|
|
529
|
+
it('will not write to console', () => {
|
|
530
|
+
const memory = createMemoryLogReporter();
|
|
531
|
+
const c = createMemoryWithConsoleLogReporter();
|
|
532
|
+
const sl = createStandardLog({ reporters: [memory, c] });
|
|
533
|
+
const log = sl.getNonConsoleLogger('non-console');
|
|
534
|
+
log.info('should not see this');
|
|
535
|
+
expect(c.logs).toEqual([]);
|
|
536
|
+
});
|
|
537
|
+
it('no non-console reporter should get logger with noop', () => {
|
|
538
|
+
const reporter = createMemoryWithConsoleLogReporter();
|
|
539
|
+
const sl = createStandardLog({ reporters: [reporter] });
|
|
540
|
+
const log = sl.getNonConsoleLogger('non-console');
|
|
541
|
+
log.emergency('should not see this');
|
|
542
|
+
log.alert('should not see this');
|
|
543
|
+
log.critical('should not see this');
|
|
544
|
+
log.error('should not see this');
|
|
545
|
+
log.warn('should not see this');
|
|
546
|
+
log.notice('should not see this');
|
|
547
|
+
log.info('should not see this');
|
|
548
|
+
log.debug('should not see this');
|
|
549
|
+
log.trace('should not see this');
|
|
550
|
+
log.planck('should not see this');
|
|
551
|
+
log.count('should not see this');
|
|
552
|
+
log.write({ id: 'x', args: ['y'], level: logLevels.alert, timestamp: new Date() });
|
|
553
|
+
log.on(logLevels.emergency, () => 'should not see this');
|
|
554
|
+
expect(reporter.logs).toEqual([]);
|
|
555
|
+
});
|
|
556
|
+
it('with existing id should fail', () => {
|
|
557
|
+
const memory = createMemoryLogReporter();
|
|
558
|
+
const c = createMemoryWithConsoleLogReporter();
|
|
559
|
+
const sl = createStandardLog({ reporters: [memory, c] });
|
|
560
|
+
sl.getLogger('exist-expected to see');
|
|
561
|
+
const log = sl.getNonConsoleLogger('exist-expected to see');
|
|
562
|
+
log.error('should not see this');
|
|
563
|
+
a.satisfies(memory.logs, [{
|
|
564
|
+
id: 'standard-log',
|
|
565
|
+
args: [`attempt to create a non-console logger with existing id ('exist-expected to see'), ignoring`],
|
|
566
|
+
level: logLevels.warn
|
|
567
|
+
}]);
|
|
568
|
+
});
|
|
569
|
+
it('will get the same non-console logger if spplies with the same name', () => {
|
|
570
|
+
const sl = createStandardLogForTest();
|
|
571
|
+
const logA = sl.getNonConsoleLogger('non-console');
|
|
572
|
+
const logB = sl.getNonConsoleLogger('non-console');
|
|
573
|
+
expect(logA).toStrictEqual(logB);
|
|
574
|
+
});
|
|
575
|
+
});
|
|
519
576
|
//# sourceMappingURL=standardLog.spec.js.map
|