nightingale 12.1.4 → 14.0.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/CHANGELOG.md +41 -0
- package/README.md +4 -0
- package/dist/definitions/config.d.ts.map +1 -0
- package/dist/definitions/index.d.ts.map +1 -0
- package/dist/definitions/index.test.d.ts +2 -0
- package/dist/definitions/index.test.d.ts.map +1 -0
- package/dist/index-browser.es.js +3 -30
- package/dist/index-browser.es.js.map +1 -1
- package/dist/index-browsermodern.es.js +1 -25
- package/dist/index-browsermodern.es.js.map +1 -1
- package/dist/{index-node14.mjs → index-node18.mjs} +2 -26
- package/dist/index-node18.mjs.map +1 -0
- package/package.json +36 -52
- package/src/config.ts +6 -3
- package/dist/config.d.ts.map +0 -1
- package/dist/index-browser.cjs.js +0 -165
- package/dist/index-browser.cjs.js.map +0 -1
- package/dist/index-node14.cjs +0 -152
- package/dist/index-node14.cjs.map +0 -1
- package/dist/index-node14.mjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/rollup.config.mjs +0 -3
- /package/dist/{config.d.ts → definitions/config.d.ts} +0 -0
- /package/dist/{index.d.ts → definitions/index.d.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,47 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [14.0.0](https://github.com/christophehurpeau/nightingale/compare/v13.0.0...v14.0.0) (2023-06-30)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### ⚠ BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* **deps:** require node 18
|
|
12
|
+
* requires node 18
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* requires node 18 ([4452b11](https://github.com/christophehurpeau/nightingale/commit/4452b116188e58c293be85e462e04922f7ad51f0))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Miscellaneous Chores
|
|
20
|
+
|
|
21
|
+
* **deps:** update dependency @pob/root to v8 ([#760](https://github.com/christophehurpeau/nightingale/issues/760)) ([22dc3cc](https://github.com/christophehurpeau/nightingale/commit/22dc3cceabdfd465d04ee36fec8fdac31febab69))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# [13.0.0](https://github.com/christophehurpeau/nightingale/compare/v12.1.4...v13.0.0) (2022-11-19)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Code Refactoring
|
|
29
|
+
|
|
30
|
+
* drop node 14 and cjs ([9a8ca06](https://github.com/christophehurpeau/nightingale/commit/9a8ca064449ddc0d69e26543e21c2d522536c50a))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Features
|
|
34
|
+
|
|
35
|
+
* build for node 16 ([30ae3e9](https://github.com/christophehurpeau/nightingale/commit/30ae3e9c455dbad793c2f704b9d860069dc80c32))
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### BREAKING CHANGES
|
|
39
|
+
|
|
40
|
+
* dropped node 14 and cjs
|
|
41
|
+
* drop node 14
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
6
47
|
## [12.1.4](https://github.com/christophehurpeau/nightingale/compare/v12.1.3...v12.1.4) (2022-02-05)
|
|
7
48
|
|
|
8
49
|
|
package/README.md
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
10
|
<a href="https://npmjs.org/package/nightingale"><img src="https://img.shields.io/npm/v/nightingale.svg?style=flat-square"></a>
|
|
11
|
+
<a href="https://npmjs.org/package/nightingale"><img src="https://img.shields.io/npm/dw/nightingale.svg?style=flat-square"></a>
|
|
12
|
+
<a href="https://npmjs.org/package/nightingale"><img src="https://img.shields.io/node/v/nightingale.svg?style=flat-square"></a>
|
|
13
|
+
<a href="https://npmjs.org/package/nightingale"><img src="https://img.shields.io/npm/types/nightingale.svg?style=flat-square"></a>
|
|
14
|
+
<a href="https://codecov.io/gh/christophehurpeau/nightingale"><img src="https://img.shields.io/codecov/c/github/christophehurpeau/nightingale/master.svg?style=flat-square"></a>
|
|
11
15
|
</p>
|
|
12
16
|
|
|
13
17
|
## Nightingale
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwB,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAkEvE,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAQhD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,IAAI,CAI/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,GAAE,MAGP,GACA,IAAI,CAON"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.test.d.ts","sourceRoot":"","sources":["../../src/index.test.ts"],"names":[],"mappings":""}
|
package/dist/index-browser.es.js
CHANGED
|
@@ -3,11 +3,9 @@ export { Logger } from 'nightingale-logger';
|
|
|
3
3
|
export { Level, Level as levels } from 'nightingale-levels';
|
|
4
4
|
|
|
5
5
|
var globalOrWindow = typeof global !== 'undefined' ? global : window;
|
|
6
|
-
|
|
7
|
-
if ((process.env.NODE_ENV !== "production") && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
6
|
+
if (process.env.NODE_ENV !== 'production' && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
8
7
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
9
8
|
}
|
|
10
|
-
|
|
11
9
|
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
12
10
|
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
13
11
|
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
@@ -16,17 +14,14 @@ if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
|
16
14
|
processors: []
|
|
17
15
|
};
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
function clearCache() {
|
|
21
18
|
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
function handleConfig(config) {
|
|
25
21
|
if (config.keys) {
|
|
26
22
|
if (config.pattern) {
|
|
27
23
|
throw new Error('Cannot have key and pattern for the same config');
|
|
28
24
|
}
|
|
29
|
-
|
|
30
25
|
if (config.key) {
|
|
31
26
|
throw new Error('Cannot have key and keys for the same config');
|
|
32
27
|
}
|
|
@@ -34,38 +29,30 @@ function handleConfig(config) {
|
|
|
34
29
|
if (config.pattern) {
|
|
35
30
|
throw new Error('Cannot have key and pattern for the same config');
|
|
36
31
|
}
|
|
37
|
-
|
|
38
32
|
config.keys = [config.key];
|
|
39
33
|
delete config.key;
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
if (config.handler) {
|
|
43
36
|
if (config.handlers) {
|
|
44
37
|
throw new Error('Cannot have handler and handlers for the same config');
|
|
45
38
|
}
|
|
46
|
-
|
|
47
39
|
config.handlers = [config.handler];
|
|
48
40
|
delete config.handler;
|
|
49
41
|
}
|
|
50
|
-
|
|
51
42
|
if (config.processor) {
|
|
52
43
|
if (config.processors) {
|
|
53
44
|
throw new Error('Cannot have processors and processors for the same config');
|
|
54
45
|
}
|
|
55
|
-
|
|
56
46
|
config.processors = [config.processor];
|
|
57
47
|
delete config.processor;
|
|
58
48
|
}
|
|
59
|
-
|
|
60
49
|
return config;
|
|
61
50
|
}
|
|
62
|
-
|
|
63
51
|
function configure(config) {
|
|
64
52
|
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
65
53
|
// eslint-disable-next-line no-console
|
|
66
54
|
console.log('nightingale: warning: config overridden');
|
|
67
55
|
}
|
|
68
|
-
|
|
69
56
|
clearCache();
|
|
70
57
|
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
71
58
|
}
|
|
@@ -73,14 +60,10 @@ function addConfig(config, unshift) {
|
|
|
73
60
|
if (unshift === void 0) {
|
|
74
61
|
unshift = false;
|
|
75
62
|
}
|
|
76
|
-
|
|
77
63
|
config = handleConfig(config);
|
|
78
|
-
|
|
79
64
|
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
80
|
-
|
|
81
65
|
clearCache();
|
|
82
66
|
}
|
|
83
|
-
|
|
84
67
|
var configIsForKey = function configIsForKey(key) {
|
|
85
68
|
return function (config) {
|
|
86
69
|
if (config.keys) return config.keys.includes(key);
|
|
@@ -88,38 +71,30 @@ var configIsForKey = function configIsForKey(key) {
|
|
|
88
71
|
return true;
|
|
89
72
|
};
|
|
90
73
|
};
|
|
91
|
-
|
|
92
74
|
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = function (key) {
|
|
93
75
|
var globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
94
76
|
var existingCache = globalCache.get(key);
|
|
95
|
-
|
|
96
77
|
if (existingCache) {
|
|
97
78
|
return existingCache;
|
|
98
79
|
}
|
|
99
|
-
|
|
100
80
|
var loggerConfig = {
|
|
101
81
|
handlers: [],
|
|
102
82
|
processors: []
|
|
103
83
|
};
|
|
104
|
-
|
|
105
84
|
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(function (config) {
|
|
106
85
|
var _loggerConfig$handler, _loggerConfig$process;
|
|
107
|
-
|
|
108
86
|
if (config.handlers) (_loggerConfig$handler = loggerConfig.handlers).push.apply(_loggerConfig$handler, config.handlers);
|
|
109
87
|
if (config.processors) (_loggerConfig$process = loggerConfig.processors).push.apply(_loggerConfig$process, config.processors);
|
|
110
88
|
return config.stop;
|
|
111
89
|
});
|
|
112
|
-
|
|
113
90
|
globalCache.set(key, loggerConfig);
|
|
114
91
|
return loggerConfig;
|
|
115
92
|
};
|
|
116
|
-
|
|
117
93
|
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
118
94
|
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = function (key, level) {
|
|
119
95
|
var _globalOrWindow$__NIG = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key),
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
96
|
+
handlers = _globalOrWindow$__NIG.handlers,
|
|
97
|
+
processors = _globalOrWindow$__NIG.processors;
|
|
123
98
|
return {
|
|
124
99
|
handlers: handlers.filter(function (handler) {
|
|
125
100
|
return level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key));
|
|
@@ -133,12 +108,10 @@ if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
|
133
108
|
* listen to uncaughtException and unhandledRejection
|
|
134
109
|
* @param {Logger} [logger]
|
|
135
110
|
*/
|
|
136
|
-
|
|
137
111
|
function listenUnhandledErrors(logger) {
|
|
138
112
|
if (logger === void 0) {
|
|
139
113
|
logger = new Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors');
|
|
140
114
|
}
|
|
141
|
-
|
|
142
115
|
process.on('uncaughtException', function (error) {
|
|
143
116
|
logger.error('uncaughtException', {
|
|
144
117
|
error: error,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browser.es.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nconst globalOrWindow: typeof global =\n typeof global !== 'undefined' ? global : (window as typeof global);\n\nif (
|
|
1
|
+
{"version":3,"file":"index-browser.es.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler, Level } from 'nightingale-types';\n\nconst globalOrWindow: typeof global =\n typeof global !== 'undefined' ? global : (window as typeof global);\n\nif (\n process.env.NODE_ENV !== 'production' &&\n globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS\n) {\n throw new Error('nightingale: update all to ^5.0.0');\n}\n\nif (!globalOrWindow.__NIGHTINGALE_CONFIG) {\n globalOrWindow.__NIGHTINGALE_CONFIG = [];\n globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map<\n string,\n ComputedConfigForKey\n >();\n globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {\n handlers: [],\n processors: [],\n };\n}\n\nfunction clearCache(): void {\n globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();\n}\n\nfunction handleConfig(config: Config): Config {\n if (config.keys) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n if (config.key) {\n throw new Error('Cannot have key and keys for the same config');\n }\n } else if (config.key) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n config.keys = [config.key];\n delete config.key;\n }\n\n if (config.handler) {\n if (config.handlers) {\n throw new Error('Cannot have handler and handlers for the same config');\n }\n config.handlers = [config.handler];\n delete config.handler;\n }\n\n if (config.processor) {\n if (config.processors) {\n throw new Error(\n 'Cannot have processors and processors for the same config',\n );\n }\n config.processors = [config.processor];\n delete config.processor;\n }\n\n return config;\n}\n\nexport function configure(config: Config[]): void {\n if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {\n // eslint-disable-next-line no-console\n console.log('nightingale: warning: config overridden');\n }\n\n clearCache();\n globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);\n}\n\nexport function addConfig(config: Config, unshift = false): void {\n config = handleConfig(config);\n globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);\n clearCache();\n}\n\nconst configIsForKey = (key: string) => (config: Config) => {\n if (config.keys) return config.keys.includes(key);\n if (config.pattern) return config.pattern.test(key);\n return true;\n};\n\nglobalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (\n key: string,\n): ComputedConfigForKey => {\n const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;\n\n const existingCache = globalCache.get(key);\n\n if (existingCache) {\n return existingCache;\n }\n\n const loggerConfig: ComputedConfigForKey = {\n handlers: [],\n processors: [],\n };\n\n globalOrWindow.__NIGHTINGALE_CONFIG\n .filter(configIsForKey(key))\n .some((config: Config) => {\n if (config.handlers) loggerConfig.handlers.push(...config.handlers);\n if (config.processors) loggerConfig.processors.push(...config.processors);\n return config.stop;\n });\n\n globalCache.set(key, loggerConfig);\n return loggerConfig;\n};\n\nif (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {\n globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (\n key: string,\n level: Level,\n ): ComputedConfigForKey => {\n const { handlers, processors }: ComputedConfigForKey =\n globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);\n\n return {\n handlers: handlers.filter(\n (handler: Handler) =>\n level >= handler.minLevel &&\n (!handler.isHandling || handler.isHandling(level, key)),\n ),\n processors,\n };\n };\n}\n","import { Logger } from 'nightingale-logger';\n\nexport { Logger } from 'nightingale-logger';\nexport { Level, Level as levels } from 'nightingale-levels';\nexport { configure, addConfig } from './config';\n\n/**\n * listen to uncaughtException and unhandledRejection\n * @param {Logger} [logger]\n */\nexport function listenUnhandledErrors(\n logger: Logger = new Logger(\n 'nightingale:listenUnhandledErrors',\n 'UnhandledErrors',\n ),\n): void {\n process.on('uncaughtException', (error) => {\n logger.error('uncaughtException', { error, unhandled: true });\n });\n process.on('unhandledRejection', (error) => {\n logger.error('unhandledRejection', { error, unhandled: true });\n });\n}\n"],"names":["globalOrWindow","global","window","process","env","NODE_ENV","__NIGHTINGALE_GLOBAL_HANDLERS","Error","__NIGHTINGALE_CONFIG","__NIGHTINGALE_LOGGER_MAP_CACHE","Map","__NIGHTINGALE_CONFIG_DEFAULT","handlers","processors","clearCache","clear","handleConfig","config","keys","pattern","key","handler","processor","configure","length","console","log","map","addConfig","unshift","configIsForKey","includes","test","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER","globalCache","existingCache","get","loggerConfig","filter","some","_loggerConfig$handler","_loggerConfig$process","push","apply","stop","set","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD","level","_globalOrWindow$__NIG","minLevel","isHandling","listenUnhandledErrors","logger","Logger","on","error","unhandled"],"mappings":";;;;AAGA,IAAMA,cAA6B,GACjC,OAAOC,MAAM,KAAK,WAAW,GAAGA,MAAM,GAAIC,MAAwB,CAAA;AAEpE,IACEC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,IACrCL,cAAc,CAACM,6BAA6B,EAC5C;AACA,EAAA,MAAM,IAAIC,KAAK,CAAC,mCAAmC,CAAC,CAAA;AACtD,CAAA;AAEA,IAAI,CAACP,cAAc,CAACQ,oBAAoB,EAAE;EACxCR,cAAc,CAACQ,oBAAoB,GAAG,EAAE,CAAA;AACxCR,EAAAA,cAAc,CAACS,8BAA8B,GAAG,IAAIC,GAAG,EAGpD,CAAA;EACHV,cAAc,CAACW,4BAA4B,GAAG;AAC5CC,IAAAA,QAAQ,EAAE,EAAE;AACZC,IAAAA,UAAU,EAAE,EAAA;GACb,CAAA;AACH,CAAA;AAEA,SAASC,UAAUA,GAAS;AAC1Bd,EAAAA,cAAc,CAACS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O,CAAC4B,QAAQ,KACxB,CAAC5B,OAAO,CAAC6B,UAAU,IAAI7B,OAAO,CAAC6B,UAAU,CAACH,KAAK,EAAE3B,GAAG,CAAC,CAAC,CAAA;AAAA,OAC3D,CAAC;AACDP,MAAAA,UAAU,EAAVA,UAAAA;KACD,CAAA;GACF,CAAA;AACH;;AC/HA;AACA;AACA;AACA;AACO,SAASsC,qBAAqBA,CACnCC,MAAc,EAIR;AAAA,EAAA,IAJNA,MAAc,KAAA,KAAA,CAAA,EAAA;AAAdA,IAAAA,MAAc,GAAG,IAAIC,MAAM,CACzB,mCAAmC,EACnC,iBACF,CAAC,CAAA;AAAA,GAAA;AAEDlD,EAAAA,OAAO,CAACmD,EAAE,CAAC,mBAAmB,EAAE,UAACC,KAAK,EAAK;AACzCH,IAAAA,MAAM,CAACG,KAAK,CAAC,mBAAmB,EAAE;AAAEA,MAAAA,KAAK,EAALA,KAAK;AAAEC,MAAAA,SAAS,EAAE,IAAA;AAAK,KAAC,CAAC,CAAA;AAC/D,GAAC,CAAC,CAAA;AACFrD,EAAAA,OAAO,CAACmD,EAAE,CAAC,oBAAoB,EAAE,UAACC,KAAK,EAAK;AAC1CH,IAAAA,MAAM,CAACG,KAAK,CAAC,oBAAoB,EAAE;AAAEA,MAAAA,KAAK,EAALA,KAAK;AAAEC,MAAAA,SAAS,EAAE,IAAA;AAAK,KAAC,CAAC,CAAA;AAChE,GAAC,CAAC,CAAA;AACJ;;;;"}
|
|
@@ -3,11 +3,9 @@ export { Logger } from 'nightingale-logger';
|
|
|
3
3
|
export { Level, Level as levels } from 'nightingale-levels';
|
|
4
4
|
|
|
5
5
|
const globalOrWindow = typeof global !== 'undefined' ? global : window;
|
|
6
|
-
|
|
7
|
-
if ((process.env.NODE_ENV !== "production") && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
6
|
+
if (process.env.NODE_ENV !== 'production' && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
8
7
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
9
8
|
}
|
|
10
|
-
|
|
11
9
|
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
12
10
|
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
13
11
|
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
@@ -16,17 +14,14 @@ if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
|
16
14
|
processors: []
|
|
17
15
|
};
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
function clearCache() {
|
|
21
18
|
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
function handleConfig(config) {
|
|
25
21
|
if (config.keys) {
|
|
26
22
|
if (config.pattern) {
|
|
27
23
|
throw new Error('Cannot have key and pattern for the same config');
|
|
28
24
|
}
|
|
29
|
-
|
|
30
25
|
if (config.key) {
|
|
31
26
|
throw new Error('Cannot have key and keys for the same config');
|
|
32
27
|
}
|
|
@@ -34,85 +29,67 @@ function handleConfig(config) {
|
|
|
34
29
|
if (config.pattern) {
|
|
35
30
|
throw new Error('Cannot have key and pattern for the same config');
|
|
36
31
|
}
|
|
37
|
-
|
|
38
32
|
config.keys = [config.key];
|
|
39
33
|
delete config.key;
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
if (config.handler) {
|
|
43
36
|
if (config.handlers) {
|
|
44
37
|
throw new Error('Cannot have handler and handlers for the same config');
|
|
45
38
|
}
|
|
46
|
-
|
|
47
39
|
config.handlers = [config.handler];
|
|
48
40
|
delete config.handler;
|
|
49
41
|
}
|
|
50
|
-
|
|
51
42
|
if (config.processor) {
|
|
52
43
|
if (config.processors) {
|
|
53
44
|
throw new Error('Cannot have processors and processors for the same config');
|
|
54
45
|
}
|
|
55
|
-
|
|
56
46
|
config.processors = [config.processor];
|
|
57
47
|
delete config.processor;
|
|
58
48
|
}
|
|
59
|
-
|
|
60
49
|
return config;
|
|
61
50
|
}
|
|
62
|
-
|
|
63
51
|
function configure(config) {
|
|
64
52
|
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
65
53
|
// eslint-disable-next-line no-console
|
|
66
54
|
console.log('nightingale: warning: config overridden');
|
|
67
55
|
}
|
|
68
|
-
|
|
69
56
|
clearCache();
|
|
70
57
|
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
71
58
|
}
|
|
72
59
|
function addConfig(config, unshift = false) {
|
|
73
60
|
config = handleConfig(config);
|
|
74
|
-
|
|
75
61
|
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
76
|
-
|
|
77
62
|
clearCache();
|
|
78
63
|
}
|
|
79
|
-
|
|
80
64
|
const configIsForKey = key => config => {
|
|
81
65
|
if (config.keys) return config.keys.includes(key);
|
|
82
66
|
if (config.pattern) return config.pattern.test(key);
|
|
83
67
|
return true;
|
|
84
68
|
};
|
|
85
|
-
|
|
86
69
|
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
87
70
|
const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
88
71
|
const existingCache = globalCache.get(key);
|
|
89
|
-
|
|
90
72
|
if (existingCache) {
|
|
91
73
|
return existingCache;
|
|
92
74
|
}
|
|
93
|
-
|
|
94
75
|
const loggerConfig = {
|
|
95
76
|
handlers: [],
|
|
96
77
|
processors: []
|
|
97
78
|
};
|
|
98
|
-
|
|
99
79
|
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
|
|
100
80
|
if (config.handlers) loggerConfig.handlers.push(...config.handlers);
|
|
101
81
|
if (config.processors) loggerConfig.processors.push(...config.processors);
|
|
102
82
|
return config.stop;
|
|
103
83
|
});
|
|
104
|
-
|
|
105
84
|
globalCache.set(key, loggerConfig);
|
|
106
85
|
return loggerConfig;
|
|
107
86
|
};
|
|
108
|
-
|
|
109
87
|
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
110
88
|
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
|
|
111
89
|
const {
|
|
112
90
|
handlers,
|
|
113
91
|
processors
|
|
114
92
|
} = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
|
|
115
|
-
|
|
116
93
|
return {
|
|
117
94
|
handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
|
|
118
95
|
processors
|
|
@@ -124,7 +101,6 @@ if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
|
124
101
|
* listen to uncaughtException and unhandledRejection
|
|
125
102
|
* @param {Logger} [logger]
|
|
126
103
|
*/
|
|
127
|
-
|
|
128
104
|
function listenUnhandledErrors(logger = new Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
|
|
129
105
|
process.on('uncaughtException', error => {
|
|
130
106
|
logger.error('uncaughtException', {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browsermodern.es.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nconst globalOrWindow: typeof global =\n typeof global !== 'undefined' ? global : (window as typeof global);\n\nif (
|
|
1
|
+
{"version":3,"file":"index-browsermodern.es.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler, Level } from 'nightingale-types';\n\nconst globalOrWindow: typeof global =\n typeof global !== 'undefined' ? global : (window as typeof global);\n\nif (\n process.env.NODE_ENV !== 'production' &&\n globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS\n) {\n throw new Error('nightingale: update all to ^5.0.0');\n}\n\nif (!globalOrWindow.__NIGHTINGALE_CONFIG) {\n globalOrWindow.__NIGHTINGALE_CONFIG = [];\n globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map<\n string,\n ComputedConfigForKey\n >();\n globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {\n handlers: [],\n processors: [],\n };\n}\n\nfunction clearCache(): void {\n globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();\n}\n\nfunction handleConfig(config: Config): Config {\n if (config.keys) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n if (config.key) {\n throw new Error('Cannot have key and keys for the same config');\n }\n } else if (config.key) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n config.keys = [config.key];\n delete config.key;\n }\n\n if (config.handler) {\n if (config.handlers) {\n throw new Error('Cannot have handler and handlers for the same config');\n }\n config.handlers = [config.handler];\n delete config.handler;\n }\n\n if (config.processor) {\n if (config.processors) {\n throw new Error(\n 'Cannot have processors and processors for the same config',\n );\n }\n config.processors = [config.processor];\n delete config.processor;\n }\n\n return config;\n}\n\nexport function configure(config: Config[]): void {\n if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {\n // eslint-disable-next-line no-console\n console.log('nightingale: warning: config overridden');\n }\n\n clearCache();\n globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);\n}\n\nexport function addConfig(config: Config, unshift = false): void {\n config = handleConfig(config);\n globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);\n clearCache();\n}\n\nconst configIsForKey = (key: string) => (config: Config) => {\n if (config.keys) return config.keys.includes(key);\n if (config.pattern) return config.pattern.test(key);\n return true;\n};\n\nglobalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (\n key: string,\n): ComputedConfigForKey => {\n const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;\n\n const existingCache = globalCache.get(key);\n\n if (existingCache) {\n return existingCache;\n }\n\n const loggerConfig: ComputedConfigForKey = {\n handlers: [],\n processors: [],\n };\n\n globalOrWindow.__NIGHTINGALE_CONFIG\n .filter(configIsForKey(key))\n .some((config: Config) => {\n if (config.handlers) loggerConfig.handlers.push(...config.handlers);\n if (config.processors) loggerConfig.processors.push(...config.processors);\n return config.stop;\n });\n\n globalCache.set(key, loggerConfig);\n return loggerConfig;\n};\n\nif (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {\n globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (\n key: string,\n level: Level,\n ): ComputedConfigForKey => {\n const { handlers, processors }: ComputedConfigForKey =\n globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);\n\n return {\n handlers: handlers.filter(\n (handler: Handler) =>\n level >= handler.minLevel &&\n (!handler.isHandling || handler.isHandling(level, key)),\n ),\n processors,\n };\n };\n}\n","import { Logger } from 'nightingale-logger';\n\nexport { Logger } from 'nightingale-logger';\nexport { Level, Level as levels } from 'nightingale-levels';\nexport { configure, addConfig } from './config';\n\n/**\n * listen to uncaughtException and unhandledRejection\n * @param {Logger} [logger]\n */\nexport function listenUnhandledErrors(\n logger: Logger = new Logger(\n 'nightingale:listenUnhandledErrors',\n 'UnhandledErrors',\n ),\n): void {\n process.on('uncaughtException', (error) => {\n logger.error('uncaughtException', { error, unhandled: true });\n });\n process.on('unhandledRejection', (error) => {\n logger.error('unhandledRejection', { error, unhandled: true });\n });\n}\n"],"names":["globalOrWindow","global","window","process","env","NODE_ENV","__NIGHTINGALE_GLOBAL_HANDLERS","Error","__NIGHTINGALE_CONFIG","__NIGHTINGALE_LOGGER_MAP_CACHE","Map","__NIGHTINGALE_CONFIG_DEFAULT","handlers","processors","clearCache","clear","handleConfig","config","keys","pattern","key","handler","processor","configure","length","console","log","map","addConfig","unshift","configIsForKey","includes","test","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER","globalCache","existingCache","get","loggerConfig","filter","some","push","stop","set","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD","level","minLevel","isHandling","listenUnhandledErrors","logger","Logger","on","error","unhandled"],"mappings":";;;;AAGA,MAAMA,cAA6B,GACjC,OAAOC,MAAM,KAAK,WAAW,GAAGA,MAAM,GAAIC,MAAwB,CAAA;AAEpE,IACEC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,IACrCL,cAAc,CAACM,6BAA6B,EAC5C;AACA,EAAA,MAAM,IAAIC,KAAK,CAAC,mCAAmC,CAAC,CAAA;AACtD,CAAA;AAEA,IAAI,CAACP,cAAc,CAACQ,oBAAoB,EAAE;EACxCR,cAAc,CAACQ,oBAAoB,GAAG,EAAE,CAAA;AACxCR,EAAAA,cAAc,CAACS,8BAA8B,GAAG,IAAIC,GAAG,EAGpD,CAAA;EACHV,cAAc,CAACW,4BAA4B,GAAG;AAC5CC,IAAAA,QAAQ,EAAE,EAAE;AACZC,IAAAA,UAAU,EAAE,EAAA;GACb,CAAA;AACH,CAAA;AAEA,SAASC,UAAUA,GAAS;AAC1Bd,EAAAA,cAAc,CAACS,8BAA8B,CAACM,KAAK,EAAE,CAAA;AACvD,CAAA;AAEA,SAASC,YAAYA,CAACC,MAAc,EAAU;EAC5C,IAAIA,MAAM,CAACC,IAAI,EAAE;IACf,IAAID,MAAM,CAACE,OAAO,EAAE;AAClB,MAAA,MAAM,IAAIZ,KAAK,CAAC,iDAAiD,CAAC,CAAA;AACpE,KAAA;IACA,IAAIU,MAAM,CAACG,GAAG,EAAE;AACd,MAAA,MAAM,IAAIb,KAAK,CAAC,8CAA8C,CAAC,CAAA;AACjE,KAAA;AACF,GAAC,MAAM,IAAIU,MAAM,CAACG,GAAG,EAAE;IACrB,IAAIH,MAAM,CAACE,OAAO,EAAE;AAClB,MAAA,MAAM,IAAIZ,KAAK,CAAC,iDAAiD,CAAC,CAAA;AACpE,KAAA;AACAU,IAAAA,MAAM,CAACC,IAAI,GAAG,CAACD,MAAM,CAACG,GAAG,CAAC,CAAA;IAC1B,OAAOH,MA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CAA0C,EAAE;AAC7D3C,EAAAA,cAAc,CAAC2C,0CAA0C,GAAG,CAC1DvB,GAAW,EACXwB,KAAY,KACa;IACzB,MAAM;MAAEhC,QAAQ;AAAEC,MAAAA,UAAAA;AAAiC,KAAC,GAClDb,cAAc,CAACiC,mCAAmC,CAACb,GAAG,CAAC,CAAA;IAEzD,OAAO;MACLR,QAAQ,EAAEA,QAAQ,CAAC0B,MAAM,CACtBjB,OAAgB,IACfuB,KAAK,IAAIvB,OAAO,CAACwB,QAAQ,KACxB,CAACxB,OAAO,CAACyB,UAAU,IAAIzB,OAAO,CAACyB,UAAU,CAACF,KAAK,EAAExB,GAAG,CAAC,CAC1D,CAAC;AACDP,MAAAA,UAAAA;KACD,CAAA;GACF,CAAA;AACH;;AC/HA;AACA;AACA;AACA;AACO,SAASkC,qBAAqBA,CACnCC,MAAc,GAAG,IAAIC,MAAM,CACzB,mCAAmC,EACnC,iBACF,CAAC,EACK;AACN9C,EAAAA,OAAO,CAAC+C,EAAE,CAAC,mBAAmB,EAAGC,KAAK,IAAK;AACzCH,IAAAA,MAAM,CAACG,KAAK,CAAC,mBAAmB,EAAE;MAAEA,KAAK;AAAEC,MAAAA,SAAS,EAAE,IAAA;AAAK,KAAC,CAAC,CAAA;AAC/D,GAAC,CAAC,CAAA;AACFjD,EAAAA,OAAO,CAAC+C,EAAE,CAAC,oBAAoB,EAAGC,KAAK,IAAK;AAC1CH,IAAAA,MAAM,CAACG,KAAK,CAAC,oBAAoB,EAAE;MAAEA,KAAK;AAAEC,MAAAA,SAAS,EAAE,IAAA;AAAK,KAAC,CAAC,CAAA;AAChE,GAAC,CAAC,CAAA;AACJ;;;;"}
|
|
@@ -3,11 +3,9 @@ export { Logger } from 'nightingale-logger';
|
|
|
3
3
|
export { Level, Level as levels } from 'nightingale-levels';
|
|
4
4
|
|
|
5
5
|
const globalOrWindow = typeof global !== 'undefined' ? global : window;
|
|
6
|
-
|
|
7
|
-
if ((process.env.NODE_ENV !== "production") && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
6
|
+
if (process.env.NODE_ENV !== 'production' && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
8
7
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
9
8
|
}
|
|
10
|
-
|
|
11
9
|
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
12
10
|
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
13
11
|
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
@@ -16,17 +14,14 @@ if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
|
16
14
|
processors: []
|
|
17
15
|
};
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
function clearCache() {
|
|
21
18
|
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
function handleConfig(config) {
|
|
25
21
|
if (config.keys) {
|
|
26
22
|
if (config.pattern) {
|
|
27
23
|
throw new Error('Cannot have key and pattern for the same config');
|
|
28
24
|
}
|
|
29
|
-
|
|
30
25
|
if (config.key) {
|
|
31
26
|
throw new Error('Cannot have key and keys for the same config');
|
|
32
27
|
}
|
|
@@ -34,85 +29,67 @@ function handleConfig(config) {
|
|
|
34
29
|
if (config.pattern) {
|
|
35
30
|
throw new Error('Cannot have key and pattern for the same config');
|
|
36
31
|
}
|
|
37
|
-
|
|
38
32
|
config.keys = [config.key];
|
|
39
33
|
delete config.key;
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
if (config.handler) {
|
|
43
36
|
if (config.handlers) {
|
|
44
37
|
throw new Error('Cannot have handler and handlers for the same config');
|
|
45
38
|
}
|
|
46
|
-
|
|
47
39
|
config.handlers = [config.handler];
|
|
48
40
|
delete config.handler;
|
|
49
41
|
}
|
|
50
|
-
|
|
51
42
|
if (config.processor) {
|
|
52
43
|
if (config.processors) {
|
|
53
44
|
throw new Error('Cannot have processors and processors for the same config');
|
|
54
45
|
}
|
|
55
|
-
|
|
56
46
|
config.processors = [config.processor];
|
|
57
47
|
delete config.processor;
|
|
58
48
|
}
|
|
59
|
-
|
|
60
49
|
return config;
|
|
61
50
|
}
|
|
62
|
-
|
|
63
51
|
function configure(config) {
|
|
64
52
|
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
65
53
|
// eslint-disable-next-line no-console
|
|
66
54
|
console.log('nightingale: warning: config overridden');
|
|
67
55
|
}
|
|
68
|
-
|
|
69
56
|
clearCache();
|
|
70
57
|
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
71
58
|
}
|
|
72
59
|
function addConfig(config, unshift = false) {
|
|
73
60
|
config = handleConfig(config);
|
|
74
|
-
|
|
75
61
|
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
76
|
-
|
|
77
62
|
clearCache();
|
|
78
63
|
}
|
|
79
|
-
|
|
80
64
|
const configIsForKey = key => config => {
|
|
81
65
|
if (config.keys) return config.keys.includes(key);
|
|
82
66
|
if (config.pattern) return config.pattern.test(key);
|
|
83
67
|
return true;
|
|
84
68
|
};
|
|
85
|
-
|
|
86
69
|
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
87
70
|
const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
88
71
|
const existingCache = globalCache.get(key);
|
|
89
|
-
|
|
90
72
|
if (existingCache) {
|
|
91
73
|
return existingCache;
|
|
92
74
|
}
|
|
93
|
-
|
|
94
75
|
const loggerConfig = {
|
|
95
76
|
handlers: [],
|
|
96
77
|
processors: []
|
|
97
78
|
};
|
|
98
|
-
|
|
99
79
|
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
|
|
100
80
|
if (config.handlers) loggerConfig.handlers.push(...config.handlers);
|
|
101
81
|
if (config.processors) loggerConfig.processors.push(...config.processors);
|
|
102
82
|
return config.stop;
|
|
103
83
|
});
|
|
104
|
-
|
|
105
84
|
globalCache.set(key, loggerConfig);
|
|
106
85
|
return loggerConfig;
|
|
107
86
|
};
|
|
108
|
-
|
|
109
87
|
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
110
88
|
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
|
|
111
89
|
const {
|
|
112
90
|
handlers,
|
|
113
91
|
processors
|
|
114
92
|
} = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
|
|
115
|
-
|
|
116
93
|
return {
|
|
117
94
|
handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
|
|
118
95
|
processors
|
|
@@ -124,7 +101,6 @@ if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
|
124
101
|
* listen to uncaughtException and unhandledRejection
|
|
125
102
|
* @param {Logger} [logger]
|
|
126
103
|
*/
|
|
127
|
-
|
|
128
104
|
function listenUnhandledErrors(logger = new Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
|
|
129
105
|
process.on('uncaughtException', error => {
|
|
130
106
|
logger.error('uncaughtException', {
|
|
@@ -141,4 +117,4 @@ function listenUnhandledErrors(logger = new Logger('nightingale:listenUnhandledE
|
|
|
141
117
|
}
|
|
142
118
|
|
|
143
119
|
export { addConfig, configure, listenUnhandledErrors };
|
|
144
|
-
//# sourceMappingURL=index-
|
|
120
|
+
//# sourceMappingURL=index-node18.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-node18.mjs","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler, Level } from 'nightingale-types';\n\nconst globalOrWindow: typeof global =\n typeof global !== 'undefined' ? global : (window as typeof global);\n\nif (\n process.env.NODE_ENV !== 'production' &&\n globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS\n) {\n throw new Error('nightingale: update all to ^5.0.0');\n}\n\nif (!globalOrWindow.__NIGHTINGALE_CONFIG) {\n globalOrWindow.__NIGHTINGALE_CONFIG = [];\n globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map<\n string,\n ComputedConfigForKey\n >();\n globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {\n handlers: [],\n processors: [],\n };\n}\n\nfunction clearCache(): void {\n globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();\n}\n\nfunction handleConfig(config: Config): Config {\n if (config.keys) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n if (config.key) {\n throw new Error('Cannot have key and keys for the same config');\n }\n } else if (config.key) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n config.keys = [config.key];\n delete config.key;\n }\n\n if (config.handler) {\n if (config.handlers) {\n throw new Error('Cannot have handler and handlers for the same config');\n }\n config.handlers = [config.handler];\n delete config.handler;\n }\n\n if (config.processor) {\n if (config.processors) {\n throw new Error(\n 'Cannot have processors and processors for the same config',\n );\n }\n config.processors = [config.processor];\n delete config.processor;\n }\n\n return config;\n}\n\nexport function configure(config: Config[]): void {\n if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {\n // eslint-disable-next-line no-console\n console.log('nightingale: warning: config overridden');\n }\n\n clearCache();\n globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);\n}\n\nexport function addConfig(config: Config, unshift = false): void {\n config = handleConfig(config);\n globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);\n clearCache();\n}\n\nconst configIsForKey = (key: string) => (config: Config) => {\n if (config.keys) return config.keys.includes(key);\n if (config.pattern) return config.pattern.test(key);\n return true;\n};\n\nglobalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (\n key: string,\n): ComputedConfigForKey => {\n const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;\n\n const existingCache = globalCache.get(key);\n\n if (existingCache) {\n return existingCache;\n }\n\n const loggerConfig: ComputedConfigForKey = {\n handlers: [],\n processors: [],\n };\n\n globalOrWindow.__NIGHTINGALE_CONFIG\n .filter(configIsForKey(key))\n .some((config: Config) => {\n if (config.handlers) loggerConfig.handlers.push(...config.handlers);\n if (config.processors) loggerConfig.processors.push(...config.processors);\n return config.stop;\n });\n\n globalCache.set(key, loggerConfig);\n return loggerConfig;\n};\n\nif (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {\n globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (\n key: string,\n level: Level,\n ): ComputedConfigForKey => {\n const { handlers, processors }: ComputedConfigForKey =\n globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);\n\n return {\n handlers: handlers.filter(\n (handler: Handler) =>\n level >= handler.minLevel &&\n (!handler.isHandling || handler.isHandling(level, key)),\n ),\n processors,\n };\n };\n}\n","import { Logger } from 'nightingale-logger';\n\nexport { Logger } from 'nightingale-logger';\nexport { Level, Level as levels } from 'nightingale-levels';\nexport { configure, addConfig } from './config';\n\n/**\n * listen to uncaughtException and unhandledRejection\n * @param {Logger} [logger]\n */\nexport function listenUnhandledErrors(\n logger: Logger = new Logger(\n 'nightingale:listenUnhandledErrors',\n 'UnhandledErrors',\n ),\n): void {\n process.on('uncaughtException', (error) => {\n logger.error('uncaughtException', { error, unhandled: true });\n });\n process.on('unhandledRejection', (error) => {\n logger.error('unhandledRejection', { error, unhandled: true });\n });\n}\n"],"names":["globalOrWindow","global","window","process","env","NODE_ENV","__NIGHTINGALE_GLOBAL_HANDLERS","Error","__NIGHTINGALE_CONFIG","__NIGHTINGALE_LOGGER_MAP_CACHE","Map","__NIGHTINGALE_CONFIG_DEFAULT","handlers","processors","clearCache","clear","handleConfig","config","keys","pattern","key","handler","processor","configure","length","console","log","map","addConfig","unshift","configIsForKey","includes","test","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER","globalCache","existingCache","get","loggerConfig","filter","some","push","stop","set","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD","level","minLevel","isHandling","listenUnhandledErrors","logger","Logger","on","error","unhandled"],"mappings":";;;;AAGA,MAAMA,cAA6B,GACjC,OAAOC,MAAM,KAAK,WAAW,GAAGA,MAAM,GAAIC,MAAwB,CAAA;AAEpE,IACEC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,IACrCL,cAAc,CAACM,6BAA6B,EAC5C;AACA,EAAA,MAAM,IAAIC,KAAK,CAAC,mCAAmC,CAAC,CAAA;AACtD,CAAA;AAEA,IAAI,CAACP,cAAc,CAACQ,oBAAoB,EAAE;EACxCR,cAAc,CAACQ,oBAAoB,GAAG,EAAE,CAAA;AACxCR,EAAAA,cAAc,CAACS,8BAA8B,GAAG,IAAIC,GAAG,EAGpD,CAAA;EACHV,cAAc,CAACW,4BAA4B,GAAG;AAC5CC,IAAAA,QAAQ,EAAE,EAAE;AACZC,IAAAA,UAAU,EAAE,EAAA;GACb,CAAA;AACH,CAAA;AAEA,SAASC,UAAUA,GAAS;AAC1Bd,EAAAA,cAAc,CAACS,8BAA8B,CAACM,KAAK,EAAE,CAAA;AACvD,CAAA;AAEA,SAASC,YAAYA,CAACC,MAAc,EAAU;EAC5C,IAAIA,MAAM,CAACC,IAAI,EAAE;IACf,IAAID,MAAM,CAACE,OAAO,EAAE;AAClB,MAAA,MAAM,IAAIZ,KAAK,CAAC,iDAAiD,CAAC,CAAA;AACpE,KAAA;IACA,IAAIU,MAAM,CAACG,GAAG,EAAE;AACd,MAAA,MAAM,IAAIb,KAAK,CAAC,8CAA8C,CAAC,CAAA;AACjE,KAAA;AACF,GAAC,MAAM,IAAIU,MAAM,CAACG,GAAG,EAAE;IACrB,IAAIH,MAAM,CAACE,OAAO,EAAE;AAClB,MAAA,MAAM,IAAIZ,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
|
"name": "nightingale",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.0",
|
|
4
4
|
"description": "Logger for browser and node",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logger"
|
|
@@ -15,74 +15,59 @@
|
|
|
15
15
|
"homepage": "https://github.com/christophehurpeau/nightingale",
|
|
16
16
|
"type": "module",
|
|
17
17
|
"engines": {
|
|
18
|
-
"node": "
|
|
18
|
+
"node": ">=18.12.0"
|
|
19
19
|
},
|
|
20
|
-
"browserslist":
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
"browserslist": {
|
|
21
|
+
"production": [
|
|
22
|
+
"defaults",
|
|
23
|
+
"> 0.2%",
|
|
24
|
+
"not ie < 12",
|
|
25
|
+
"not safari < 10",
|
|
26
|
+
"not ios_saf < 10"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/index-node18.mjs",
|
|
30
|
+
"types": "./dist/definitions/index.d.ts",
|
|
29
31
|
"module": "./dist/index-browser.es.js",
|
|
30
32
|
"browser": "./dist/index-browser.es.js",
|
|
31
33
|
"exports": {
|
|
32
34
|
"./package.json": "./package.json",
|
|
33
35
|
".": {
|
|
34
36
|
"node": {
|
|
35
|
-
"import": "./dist/index-
|
|
36
|
-
"require": "./dist/index-node14.cjs"
|
|
37
|
+
"import": "./dist/index-node18.mjs"
|
|
37
38
|
},
|
|
38
39
|
"browser": {
|
|
39
40
|
"browser:modern": {
|
|
40
41
|
"import": "./dist/index-browsermodern.es.js"
|
|
41
42
|
},
|
|
42
|
-
"import": "./dist/index-browser.es.js"
|
|
43
|
-
"require": "./dist/index-browser.cjs.js"
|
|
43
|
+
"import": "./dist/index-browser.es.js"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
-
"module:node": "./dist/index-node14.mjs",
|
|
48
|
-
"module:modern-browsers": "./dist/index-browsermodern.es.js",
|
|
49
47
|
"sideEffects": false,
|
|
50
48
|
"scripts": {
|
|
51
|
-
"build": "
|
|
52
|
-
"build:definitions": "tsc -p tsconfig.
|
|
53
|
-
"clean": "
|
|
49
|
+
"build": "yarn clean:build && rollup --config rollup.config.mjs && yarn run build:definitions",
|
|
50
|
+
"build:definitions": "tsc -p tsconfig.json",
|
|
51
|
+
"clean": "yarn clean:build",
|
|
52
|
+
"clean:build": "pob-babel-clean-out dist",
|
|
54
53
|
"lint": "yarn run lint:eslint",
|
|
55
|
-
"lint:eslint": "
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
"prettier": {
|
|
59
|
-
"trailingComma": "all",
|
|
60
|
-
"singleQuote": true,
|
|
61
|
-
"arrowParens": "always"
|
|
54
|
+
"lint:eslint": "yarn ../.. run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet packages/nightingale",
|
|
55
|
+
"test": "yarn ../../ run test -- packages/nightingale",
|
|
56
|
+
"watch": "yarn clean:build && rollup --config rollup.config.mjs --watch"
|
|
62
57
|
},
|
|
58
|
+
"prettier": "@pob/root/prettier-config",
|
|
63
59
|
"pob": {
|
|
64
60
|
"babelEnvs": [
|
|
65
61
|
{
|
|
66
62
|
"target": "node",
|
|
67
|
-
"version": "
|
|
68
|
-
"formats": [
|
|
69
|
-
"cjs",
|
|
70
|
-
"es"
|
|
71
|
-
]
|
|
63
|
+
"version": "18"
|
|
72
64
|
},
|
|
73
65
|
{
|
|
74
66
|
"target": "browser",
|
|
75
|
-
"version": "modern"
|
|
76
|
-
"formats": [
|
|
77
|
-
"es"
|
|
78
|
-
]
|
|
67
|
+
"version": "modern"
|
|
79
68
|
},
|
|
80
69
|
{
|
|
81
|
-
"target": "browser"
|
|
82
|
-
"formats": [
|
|
83
|
-
"cjs",
|
|
84
|
-
"es"
|
|
85
|
-
]
|
|
70
|
+
"target": "browser"
|
|
86
71
|
}
|
|
87
72
|
],
|
|
88
73
|
"entries": [
|
|
@@ -90,18 +75,17 @@
|
|
|
90
75
|
]
|
|
91
76
|
},
|
|
92
77
|
"dependencies": {
|
|
93
|
-
"@types/node": ">=
|
|
94
|
-
"nightingale-levels": "
|
|
95
|
-
"nightingale-logger": "
|
|
96
|
-
"nightingale-types": "
|
|
78
|
+
"@types/node": ">=18.0.0",
|
|
79
|
+
"nightingale-levels": "14.0.0",
|
|
80
|
+
"nightingale-logger": "14.0.0",
|
|
81
|
+
"nightingale-types": "14.0.0"
|
|
97
82
|
},
|
|
98
83
|
"devDependencies": {
|
|
99
|
-
"@babel/core": "7.
|
|
100
|
-
"@babel/preset-env": "7.
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
104
|
-
"typescript": "4.5.5"
|
|
84
|
+
"@babel/core": "7.22.5",
|
|
85
|
+
"@babel/preset-env": "7.22.5",
|
|
86
|
+
"nightingale-string": "14.0.0",
|
|
87
|
+
"pob-babel": "36.1.0",
|
|
88
|
+
"typescript": "5.1.6"
|
|
105
89
|
},
|
|
106
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "bc20e0f093a4fecd4d87f9374f6dbc375c09c25e"
|
|
107
91
|
}
|
package/src/config.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { ComputedConfigForKey, Config } from 'nightingale-logger';
|
|
2
|
-
import type { Handler } from 'nightingale-types';
|
|
2
|
+
import type { Handler, Level } from 'nightingale-types';
|
|
3
3
|
|
|
4
4
|
const globalOrWindow: typeof global =
|
|
5
5
|
typeof global !== 'undefined' ? global : (window as typeof global);
|
|
6
6
|
|
|
7
|
-
if (
|
|
7
|
+
if (
|
|
8
|
+
process.env.NODE_ENV !== 'production' &&
|
|
9
|
+
globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS
|
|
10
|
+
) {
|
|
8
11
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
9
12
|
}
|
|
10
13
|
|
|
@@ -114,7 +117,7 @@ globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (
|
|
|
114
117
|
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
115
118
|
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (
|
|
116
119
|
key: string,
|
|
117
|
-
level:
|
|
120
|
+
level: Level,
|
|
118
121
|
): ComputedConfigForKey => {
|
|
119
122
|
const { handlers, processors }: ComputedConfigForKey =
|
|
120
123
|
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
|
package/dist/config.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwB,MAAM,EAAE,MAAM,oBAAoB,CAAC;AA+DvE,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAQhD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,IAAI,CAI/D"}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var nightingaleLogger = require('nightingale-logger');
|
|
6
|
-
var nightingaleLevels = require('nightingale-levels');
|
|
7
|
-
|
|
8
|
-
var globalOrWindow = typeof global !== 'undefined' ? global : window;
|
|
9
|
-
|
|
10
|
-
if ((process.env.NODE_ENV !== "production") && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
11
|
-
throw new Error('nightingale: update all to ^5.0.0');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
15
|
-
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
16
|
-
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
17
|
-
globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
18
|
-
handlers: [],
|
|
19
|
-
processors: []
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function clearCache() {
|
|
24
|
-
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function handleConfig(config) {
|
|
28
|
-
if (config.keys) {
|
|
29
|
-
if (config.pattern) {
|
|
30
|
-
throw new Error('Cannot have key and pattern for the same config');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (config.key) {
|
|
34
|
-
throw new Error('Cannot have key and keys for the same config');
|
|
35
|
-
}
|
|
36
|
-
} else if (config.key) {
|
|
37
|
-
if (config.pattern) {
|
|
38
|
-
throw new Error('Cannot have key and pattern for the same config');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
config.keys = [config.key];
|
|
42
|
-
delete config.key;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (config.handler) {
|
|
46
|
-
if (config.handlers) {
|
|
47
|
-
throw new Error('Cannot have handler and handlers for the same config');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
config.handlers = [config.handler];
|
|
51
|
-
delete config.handler;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (config.processor) {
|
|
55
|
-
if (config.processors) {
|
|
56
|
-
throw new Error('Cannot have processors and processors for the same config');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
config.processors = [config.processor];
|
|
60
|
-
delete config.processor;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return config;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function configure(config) {
|
|
67
|
-
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
68
|
-
// eslint-disable-next-line no-console
|
|
69
|
-
console.log('nightingale: warning: config overridden');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
clearCache();
|
|
73
|
-
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
74
|
-
}
|
|
75
|
-
function addConfig(config, unshift) {
|
|
76
|
-
if (unshift === void 0) {
|
|
77
|
-
unshift = false;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
config = handleConfig(config);
|
|
81
|
-
|
|
82
|
-
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
83
|
-
|
|
84
|
-
clearCache();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
var configIsForKey = function configIsForKey(key) {
|
|
88
|
-
return function (config) {
|
|
89
|
-
if (config.keys) return config.keys.includes(key);
|
|
90
|
-
if (config.pattern) return config.pattern.test(key);
|
|
91
|
-
return true;
|
|
92
|
-
};
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = function (key) {
|
|
96
|
-
var globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
97
|
-
var existingCache = globalCache.get(key);
|
|
98
|
-
|
|
99
|
-
if (existingCache) {
|
|
100
|
-
return existingCache;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
var loggerConfig = {
|
|
104
|
-
handlers: [],
|
|
105
|
-
processors: []
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(function (config) {
|
|
109
|
-
var _loggerConfig$handler, _loggerConfig$process;
|
|
110
|
-
|
|
111
|
-
if (config.handlers) (_loggerConfig$handler = loggerConfig.handlers).push.apply(_loggerConfig$handler, config.handlers);
|
|
112
|
-
if (config.processors) (_loggerConfig$process = loggerConfig.processors).push.apply(_loggerConfig$process, config.processors);
|
|
113
|
-
return config.stop;
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
globalCache.set(key, loggerConfig);
|
|
117
|
-
return loggerConfig;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
121
|
-
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = function (key, level) {
|
|
122
|
-
var _globalOrWindow$__NIG = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key),
|
|
123
|
-
handlers = _globalOrWindow$__NIG.handlers,
|
|
124
|
-
processors = _globalOrWindow$__NIG.processors;
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
handlers: handlers.filter(function (handler) {
|
|
128
|
-
return level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key));
|
|
129
|
-
}),
|
|
130
|
-
processors: processors
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* listen to uncaughtException and unhandledRejection
|
|
137
|
-
* @param {Logger} [logger]
|
|
138
|
-
*/
|
|
139
|
-
|
|
140
|
-
function listenUnhandledErrors(logger) {
|
|
141
|
-
if (logger === void 0) {
|
|
142
|
-
logger = new nightingaleLogger.Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors');
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
process.on('uncaughtException', function (error) {
|
|
146
|
-
logger.error('uncaughtException', {
|
|
147
|
-
error: error,
|
|
148
|
-
unhandled: true
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
process.on('unhandledRejection', function (error) {
|
|
152
|
-
logger.error('unhandledRejection', {
|
|
153
|
-
error: error,
|
|
154
|
-
unhandled: true
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
exports.Logger = nightingaleLogger.Logger;
|
|
160
|
-
exports.Level = nightingaleLevels.Level;
|
|
161
|
-
exports.levels = nightingaleLevels.Level;
|
|
162
|
-
exports.addConfig = addConfig;
|
|
163
|
-
exports.configure = configure;
|
|
164
|
-
exports.listenUnhandledErrors = listenUnhandledErrors;
|
|
165
|
-
//# sourceMappingURL=index-browser.cjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-browser.cjs.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nconst globalOrWindow: typeof global =\n typeof global !== 'undefined' ? global : (window as typeof global);\n\nif (__DEV__ && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {\n throw new Error('nightingale: update all to ^5.0.0');\n}\n\nif (!globalOrWindow.__NIGHTINGALE_CONFIG) {\n globalOrWindow.__NIGHTINGALE_CONFIG = [];\n globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map<\n string,\n ComputedConfigForKey\n >();\n globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {\n handlers: [],\n processors: [],\n };\n}\n\nfunction clearCache(): void {\n globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();\n}\n\nfunction handleConfig(config: Config): Config {\n if (config.keys) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n if (config.key) {\n throw new Error('Cannot have key and keys for the same config');\n }\n } else if (config.key) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n config.keys = [config.key];\n delete config.key;\n }\n\n if (config.handler) {\n if (config.handlers) {\n throw new Error('Cannot have handler and handlers for the same config');\n }\n config.handlers = [config.handler];\n delete config.handler;\n }\n\n if (config.processor) {\n if (config.processors) {\n throw new Error(\n 'Cannot have processors and processors for the same config',\n );\n }\n config.processors = [config.processor];\n delete config.processor;\n }\n\n return config;\n}\n\nexport function configure(config: Config[]): void {\n if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {\n // eslint-disable-next-line no-console\n console.log('nightingale: warning: config overridden');\n }\n\n clearCache();\n globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);\n}\n\nexport function addConfig(config: Config, unshift = false): void {\n config = handleConfig(config);\n globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);\n clearCache();\n}\n\nconst configIsForKey = (key: string) => (config: Config) => {\n if (config.keys) return config.keys.includes(key);\n if (config.pattern) return config.pattern.test(key);\n return true;\n};\n\nglobalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (\n key: string,\n): ComputedConfigForKey => {\n const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;\n\n const existingCache = globalCache.get(key);\n\n if (existingCache) {\n return existingCache;\n }\n\n const loggerConfig: ComputedConfigForKey = {\n handlers: [],\n processors: [],\n };\n\n globalOrWindow.__NIGHTINGALE_CONFIG\n .filter(configIsForKey(key))\n .some((config: Config) => {\n if (config.handlers) loggerConfig.handlers.push(...config.handlers);\n if (config.processors) loggerConfig.processors.push(...config.processors);\n return config.stop;\n });\n\n globalCache.set(key, loggerConfig);\n return loggerConfig;\n};\n\nif (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {\n globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (\n key: string,\n level: number,\n ): ComputedConfigForKey => {\n const { handlers, processors }: ComputedConfigForKey =\n globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);\n\n return {\n handlers: handlers.filter(\n (handler: Handler) =>\n level >= handler.minLevel &&\n (!handler.isHandling || handler.isHandling(level, key)),\n ),\n processors,\n };\n };\n}\n","import { Logger } from 'nightingale-logger';\n\nexport { Logger } from 'nightingale-logger';\nexport { Level, Level as levels } from 'nightingale-levels';\nexport { configure, addConfig } from './config';\n\n/**\n * listen to uncaughtException and unhandledRejection\n * @param {Logger} [logger]\n */\nexport function listenUnhandledErrors(\n logger: Logger = new Logger(\n 'nightingale:listenUnhandledErrors',\n 'UnhandledErrors',\n ),\n): void {\n process.on('uncaughtException', (error) => {\n logger.error('uncaughtException', { error, unhandled: true });\n });\n process.on('unhandledRejection', (error) => {\n logger.error('unhandledRejection', { error, unhandled: true });\n });\n}\n"],"names":["globalOrWindow","global","window","__DEV__","__NIGHTINGALE_GLOBAL_HANDLERS","Error","__NIGHTINGALE_CONFIG","__NIGHTINGALE_LOGGER_MAP_CACHE","Map","__NIGHTINGALE_CONFIG_DEFAULT","handlers","processors","clearCache","clear","handleConfig","config","keys","pattern","key","handler","processor","configure","length","console","log","map","addConfig","unshift","configIsForKey","includes","test","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER","globalCache","existingCache","get","loggerConfig","filter","some","push","stop","set","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD","level","minLevel","isHandling","listenUnhandledErrors","logger","Logger","process","on","error","unhandled"],"mappings":";;;;;;;AAGA,IAAMA,cAA6B,GACjC,OAAOC,MAAP,KAAkB,WAAlB,GAAgCA,MAAhC,GAA0CC,MAD5C;;AAGA,IAAIC,2CAAWH,cAAc,CAACI,6BAA9B,EAA6D;AAC3D,QAAM,IAAIC,KAAJ,CAAU,mCAAV,CAAN;AACD;;AAED,IAAI,CAACL,cAAc,CAACM,oBAApB,EAA0C;AACxCN,EAAAA,cAAc,CAACM,oBAAf,GAAsC,EAAtC;AACAN,EAAAA,cAAc,CAACO,8BAAf,GAAgD,IAAIC,GAAJ,EAAhD;AAIAR,EAAAA,cAAc,CAACS,4BAAf,GAA8C;AAC5CC,IAAAA,QAAQ,EAAE,EADkC;AAE5CC,IAAAA,UAAU,EAAE;AAFgC,GAA9C;AAID;;AAED,SAASC,UAAT,GAA4B;AAC1BZ,EAAAA,cAAc,CAACO,8BAAf,CAA8CM,KAA9C;AACD;;AAED,SAASC,YAAT,CAAsBC,MAAtB,EAA8C;AAC5C,MAAIA,MAAM,CAACC,IAAX,EAAiB;AACf,QAAID,MAAM,CAACE,OAAX,EAAoB;AAClB,YAAM,IAAIZ,KAAJ,CAAU,iDAAV,CAAN;AACD;;AACD,QAAIU,MAAM,CAACG,GAAX,EAAgB;AACd,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@ -1,152 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const nightingaleLogger = require('nightingale-logger');
|
|
6
|
-
const nightingaleLevels = require('nightingale-levels');
|
|
7
|
-
|
|
8
|
-
const globalOrWindow = typeof global !== 'undefined' ? global : window;
|
|
9
|
-
|
|
10
|
-
if ((process.env.NODE_ENV !== "production") && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
11
|
-
throw new Error('nightingale: update all to ^5.0.0');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
15
|
-
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
16
|
-
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
17
|
-
globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
18
|
-
handlers: [],
|
|
19
|
-
processors: []
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function clearCache() {
|
|
24
|
-
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function handleConfig(config) {
|
|
28
|
-
if (config.keys) {
|
|
29
|
-
if (config.pattern) {
|
|
30
|
-
throw new Error('Cannot have key and pattern for the same config');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (config.key) {
|
|
34
|
-
throw new Error('Cannot have key and keys for the same config');
|
|
35
|
-
}
|
|
36
|
-
} else if (config.key) {
|
|
37
|
-
if (config.pattern) {
|
|
38
|
-
throw new Error('Cannot have key and pattern for the same config');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
config.keys = [config.key];
|
|
42
|
-
delete config.key;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (config.handler) {
|
|
46
|
-
if (config.handlers) {
|
|
47
|
-
throw new Error('Cannot have handler and handlers for the same config');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
config.handlers = [config.handler];
|
|
51
|
-
delete config.handler;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (config.processor) {
|
|
55
|
-
if (config.processors) {
|
|
56
|
-
throw new Error('Cannot have processors and processors for the same config');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
config.processors = [config.processor];
|
|
60
|
-
delete config.processor;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return config;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function configure(config) {
|
|
67
|
-
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
68
|
-
// eslint-disable-next-line no-console
|
|
69
|
-
console.log('nightingale: warning: config overridden');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
clearCache();
|
|
73
|
-
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
74
|
-
}
|
|
75
|
-
function addConfig(config, unshift = false) {
|
|
76
|
-
config = handleConfig(config);
|
|
77
|
-
|
|
78
|
-
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
79
|
-
|
|
80
|
-
clearCache();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const configIsForKey = key => config => {
|
|
84
|
-
if (config.keys) return config.keys.includes(key);
|
|
85
|
-
if (config.pattern) return config.pattern.test(key);
|
|
86
|
-
return true;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
90
|
-
const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
91
|
-
const existingCache = globalCache.get(key);
|
|
92
|
-
|
|
93
|
-
if (existingCache) {
|
|
94
|
-
return existingCache;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const loggerConfig = {
|
|
98
|
-
handlers: [],
|
|
99
|
-
processors: []
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
|
|
103
|
-
if (config.handlers) loggerConfig.handlers.push(...config.handlers);
|
|
104
|
-
if (config.processors) loggerConfig.processors.push(...config.processors);
|
|
105
|
-
return config.stop;
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
globalCache.set(key, loggerConfig);
|
|
109
|
-
return loggerConfig;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
113
|
-
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
|
|
114
|
-
const {
|
|
115
|
-
handlers,
|
|
116
|
-
processors
|
|
117
|
-
} = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
|
|
121
|
-
processors
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* listen to uncaughtException and unhandledRejection
|
|
128
|
-
* @param {Logger} [logger]
|
|
129
|
-
*/
|
|
130
|
-
|
|
131
|
-
function listenUnhandledErrors(logger = new nightingaleLogger.Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
|
|
132
|
-
process.on('uncaughtException', error => {
|
|
133
|
-
logger.error('uncaughtException', {
|
|
134
|
-
error,
|
|
135
|
-
unhandled: true
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
process.on('unhandledRejection', error => {
|
|
139
|
-
logger.error('unhandledRejection', {
|
|
140
|
-
error,
|
|
141
|
-
unhandled: true
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
exports.Logger = nightingaleLogger.Logger;
|
|
147
|
-
exports.Level = nightingaleLevels.Level;
|
|
148
|
-
exports.levels = nightingaleLevels.Level;
|
|
149
|
-
exports.addConfig = addConfig;
|
|
150
|
-
exports.configure = configure;
|
|
151
|
-
exports.listenUnhandledErrors = listenUnhandledErrors;
|
|
152
|
-
//# sourceMappingURL=index-node14.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-node14.cjs","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nconst globalOrWindow: typeof global =\n typeof global !== 'undefined' ? global : (window as typeof global);\n\nif (__DEV__ && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {\n throw new Error('nightingale: update all to ^5.0.0');\n}\n\nif (!globalOrWindow.__NIGHTINGALE_CONFIG) {\n globalOrWindow.__NIGHTINGALE_CONFIG = [];\n globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map<\n string,\n ComputedConfigForKey\n >();\n globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {\n handlers: [],\n processors: [],\n };\n}\n\nfunction clearCache(): void {\n globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();\n}\n\nfunction handleConfig(config: Config): Config {\n if (config.keys) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n if (config.key) {\n throw new Error('Cannot have key and keys for the same config');\n }\n } else if (config.key) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n config.keys = [config.key];\n delete config.key;\n }\n\n if (config.handler) {\n if (config.handlers) {\n throw new Error('Cannot have handler and handlers for the same config');\n }\n config.handlers = [config.handler];\n delete config.handler;\n }\n\n if (config.processor) {\n if (config.processors) {\n throw new Error(\n 'Cannot have processors and processors for the same config',\n );\n }\n config.processors = [config.processor];\n delete config.processor;\n }\n\n return config;\n}\n\nexport function configure(config: Config[]): void {\n if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {\n // eslint-disable-next-line no-console\n console.log('nightingale: warning: config overridden');\n }\n\n clearCache();\n globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);\n}\n\nexport function addConfig(config: Config, unshift = false): void {\n config = handleConfig(config);\n globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);\n clearCache();\n}\n\nconst configIsForKey = (key: string) => (config: Config) => {\n if (config.keys) return config.keys.includes(key);\n if (config.pattern) return config.pattern.test(key);\n return true;\n};\n\nglobalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (\n key: string,\n): ComputedConfigForKey => {\n const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;\n\n const existingCache = globalCache.get(key);\n\n if (existingCache) {\n return existingCache;\n }\n\n const loggerConfig: ComputedConfigForKey = {\n handlers: [],\n processors: [],\n };\n\n globalOrWindow.__NIGHTINGALE_CONFIG\n .filter(configIsForKey(key))\n .some((config: Config) => {\n if (config.handlers) loggerConfig.handlers.push(...config.handlers);\n if (config.processors) loggerConfig.processors.push(...config.processors);\n return config.stop;\n });\n\n globalCache.set(key, loggerConfig);\n return loggerConfig;\n};\n\nif (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {\n globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (\n key: string,\n level: number,\n ): ComputedConfigForKey => {\n const { handlers, processors }: ComputedConfigForKey =\n globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);\n\n return {\n handlers: handlers.filter(\n (handler: Handler) =>\n level >= handler.minLevel &&\n (!handler.isHandling || handler.isHandling(level, key)),\n ),\n processors,\n };\n };\n}\n","import { Logger } from 'nightingale-logger';\n\nexport { Logger } from 'nightingale-logger';\nexport { Level, Level as levels } from 'nightingale-levels';\nexport { configure, addConfig } from './config';\n\n/**\n * listen to uncaughtException and unhandledRejection\n * @param {Logger} [logger]\n */\nexport function listenUnhandledErrors(\n logger: Logger = new Logger(\n 'nightingale:listenUnhandledErrors',\n 'UnhandledErrors',\n ),\n): void {\n process.on('uncaughtException', (error) => {\n logger.error('uncaughtException', { error, unhandled: true });\n });\n process.on('unhandledRejection', (error) => {\n logger.error('unhandledRejection', { error, unhandled: true });\n });\n}\n"],"names":["globalOrWindow","global","window","__DEV__","__NIGHTINGALE_GLOBAL_HANDLERS","Error","__NIGHTINGALE_CONFIG","__NIGHTINGALE_LOGGER_MAP_CACHE","Map","__NIGHTINGALE_CONFIG_DEFAULT","handlers","processors","clearCache","clear","handleConfig","config","keys","pattern","key","handler","processor","configure","length","console","log","map","addConfig","unshift","configIsForKey","includes","test","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER","globalCache","existingCache","get","loggerConfig","filter","some","push","stop","set","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD","level","minLevel","isHandling","listenUnhandledErrors","logger","Logger","process","on","error","unhandled"],"mappings":";;;;;;;AAGA,MAAMA,cAA6B,GACjC,OAAOC,MAAP,KAAkB,WAAlB,GAAgCA,MAAhC,GAA0CC,MAD5C;;AAGA,IAAIC,2CAAWH,cAAc,CAACI,6BAA9B,EAA6D;AAC3D,QAAM,IAAIC,KAAJ,CAAU,mCAAV,CAAN;AACD;;AAED,IAAI,CAACL,cAAc,CAACM,oBAApB,EAA0C;AACxCN,EAAAA,cAAc,CAACM,oBAAf,GAAsC,EAAtC;AACAN,EAAAA,cAAc,CAACO,8BAAf,GAAgD,IAAIC,GAAJ,EAAhD;AAIAR,EAAAA,cAAc,CAACS,4BAAf,GAA8C;AAC5CC,IAAAA,QAAQ,EAAE,EADkC;AAE5CC,IAAAA,UAAU,EAAE;AAFgC,GAA9C;AAID;;AAED,SAASC,UAAT,GAA4B;AAC1BZ,EAAAA,cAAc,CAACO,8BAAf,CAA8CM,KAA9C;AACD;;AAED,SAASC,YAAT,CAAsBC,MAAtB,EAA8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P,EAAAA,WAAW,CAACQ,GAAZ,CAAgBtB,GAAhB,EAAqBiB,YAArB;AACA,SAAOA,YAAP;AACD,CA1BD;;AA4BA,IAAInC,cAAc,CAACyC,0CAAnB,EAA+D;AAC7DzC,EAAAA,cAAc,CAACyC,0CAAf,GAA4D,CAC1DvB,GAD0D,EAE1DwB,KAF0D,KAGjC;AACzB,UAAM;AAAEhC,MAAAA,QAAF;AAAYC,MAAAA;AAAZ,QACJX,cAAc,CAAC+B,mCAAf,CAAmDb,GAAnD,CADF;;AAGA,WAAO;AACLR,MAAAA,QAAQ,EAAEA,QAAQ,CAAC0B,MAAT,CACPjB,OAAD,IACEuB,KAAK,IAAIvB,OAAO,CAACwB,QAAjB,KACC,CAACxB,OAAO,CAACyB,UAAT,IAAuBzB,OAAO,CAACyB,UAAR,CAAmBF,KAAnB,EAA0BxB,GAA1B,CADxB,CAFM,CADL;AAMLP,MAAAA;AANK,KAAP;AAQD,GAfD;AAgBD;;AC5HD;AACA;AACA;AACA;;AACO,SAASkC,qBAAT,CACLC,MAAc,GAAG,IAAIC,wBAAJ,CACf,mCADe,EAEf,iBAFe,CADZ,EAKC;AACNC,EAAAA,OAAO,CAACC,EAAR,CAAW,mBAAX,EAAiCC,KAAD,IAAW;AACzCJ,IAAAA,MAAM,CAACI,KAAP,CAAa,mBAAb,EAAkC;AAAEA,MAAAA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAlC;AACD,GAFD;AAGAH,EAAAA,OAAO,CAACC,EAAR,CAAW,oBAAX,EAAkCC,KAAD,IAAW;AAC1CJ,IAAAA,MAAM,CAACI,KAAP,CAAa,oBAAb,EAAmC;AAAEA,MAAAA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAnC;AACD,GAFD;AAGD;;;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-node14.mjs","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nconst globalOrWindow: typeof global =\n typeof global !== 'undefined' ? global : (window as typeof global);\n\nif (__DEV__ && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {\n throw new Error('nightingale: update all to ^5.0.0');\n}\n\nif (!globalOrWindow.__NIGHTINGALE_CONFIG) {\n globalOrWindow.__NIGHTINGALE_CONFIG = [];\n globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map<\n string,\n ComputedConfigForKey\n >();\n globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {\n handlers: [],\n processors: [],\n };\n}\n\nfunction clearCache(): void {\n globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();\n}\n\nfunction handleConfig(config: Config): Config {\n if (config.keys) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n if (config.key) {\n throw new Error('Cannot have key and keys for the same config');\n }\n } else if (config.key) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n config.keys = [config.key];\n delete config.key;\n }\n\n if (config.handler) {\n if (config.handlers) {\n throw new Error('Cannot have handler and handlers for the same config');\n }\n config.handlers = [config.handler];\n delete config.handler;\n }\n\n if (config.processor) {\n if (config.processors) {\n throw new Error(\n 'Cannot have processors and processors for the same config',\n );\n }\n config.processors = [config.processor];\n delete config.processor;\n }\n\n return config;\n}\n\nexport function configure(config: Config[]): void {\n if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {\n // eslint-disable-next-line no-console\n console.log('nightingale: warning: config overridden');\n }\n\n clearCache();\n globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);\n}\n\nexport function addConfig(config: Config, unshift = false): void {\n config = handleConfig(config);\n globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);\n clearCache();\n}\n\nconst configIsForKey = (key: string) => (config: Config) => {\n if (config.keys) return config.keys.includes(key);\n if (config.pattern) return config.pattern.test(key);\n return true;\n};\n\nglobalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (\n key: string,\n): ComputedConfigForKey => {\n const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;\n\n const existingCache = globalCache.get(key);\n\n if (existingCache) {\n return existingCache;\n }\n\n const loggerConfig: ComputedConfigForKey = {\n handlers: [],\n processors: [],\n };\n\n globalOrWindow.__NIGHTINGALE_CONFIG\n .filter(configIsForKey(key))\n .some((config: Config) => {\n if (config.handlers) loggerConfig.handlers.push(...config.handlers);\n if (config.processors) loggerConfig.processors.push(...config.processors);\n return config.stop;\n });\n\n globalCache.set(key, loggerConfig);\n return loggerConfig;\n};\n\nif (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {\n globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (\n key: string,\n level: number,\n ): ComputedConfigForKey => {\n const { handlers, processors }: ComputedConfigForKey =\n globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);\n\n return {\n handlers: handlers.filter(\n (handler: Handler) =>\n level >= handler.minLevel &&\n (!handler.isHandling || handler.isHandling(level, key)),\n ),\n processors,\n };\n };\n}\n","import { Logger } from 'nightingale-logger';\n\nexport { Logger } from 'nightingale-logger';\nexport { Level, Level as levels } from 'nightingale-levels';\nexport { configure, addConfig } from './config';\n\n/**\n * listen to uncaughtException and unhandledRejection\n * @param {Logger} [logger]\n */\nexport function listenUnhandledErrors(\n logger: Logger = new Logger(\n 'nightingale:listenUnhandledErrors',\n 'UnhandledErrors',\n ),\n): void {\n process.on('uncaughtException', (error) => {\n logger.error('uncaughtException', { error, unhandled: true });\n });\n process.on('unhandledRejection', (error) => {\n logger.error('unhandledRejection', { error, unhandled: true });\n });\n}\n"],"names":["globalOrWindow","global","window","__DEV__","__NIGHTINGALE_GLOBAL_HANDLERS","Error","__NIGHTINGALE_CONFIG","__NIGHTINGALE_LOGGER_MAP_CACHE","Map","__NIGHTINGALE_CONFIG_DEFAULT","handlers","processors","clearCache","clear","handleConfig","config","keys","pattern","key","handler","processor","configure","length","console","log","map","addConfig","unshift","configIsForKey","includes","test","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER","globalCache","existingCache","get","loggerConfig","filter","some","push","stop","set","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD","level","minLevel","isHandling","listenUnhandledErrors","logger","Logger","process","on","error","unhandled"],"mappings":";;;;AAGA,MAAMA,cAA6B,GACjC,OAAOC,MAAP,KAAkB,WAAlB,GAAgCA,MAAhC,GAA0CC,MAD5C;;AAGA,IAAIC,2CAAWH,cAAc,CAACI,6BAA9B,EAA6D;AAC3D,QAAM,IAAIC,KAAJ,CAAU,mCAAV,CAAN;AACD;;AAED,IAAI,CAACL,cAAc,CAACM,oBAApB,EAA0C;AACxCN,EAAAA,cAAc,CAACM,oBAAf,GAAsC,EAAtC;AACAN,EAAAA,cAAc,CAACO,8BAAf,GAAgD,IAAIC,GAAJ,EAAhD;AAIAR,EAAAA,cAAc,CAACS,4BAAf,GAA8C;AAC5CC,IAAAA,QAAQ,EAAE,EADkC;AAE5CC,IAAAA,UAAU,EAAE;AAFgC,GAA9C;AAID;;AAED,SAASC,UAAT,GAA4B;AAC1BZ,EAAAA,cAAc,CAACO,8BAAf,CAA8CM,KAA9C;AACD;;AAED,SAASC,YAAT,CAAsBC,MAAtB,EAA8C;AAC5C,MAAIA,MAAM,CAACC,IAAX,EAAiB;AACf,QAAID,MAAM,CAACE,OAAX,EAAoB;AAClB,YAAM,IAAIZ,KAAJ,CAAU,iDAAV,CAAN;AACD;;AACD,QAAIU,MAAM,CAACG,GAAX,EAAgB;AACd,YAAM,IAAIb,KAAJ,CAAU,8CAAV,CAAN;AACD;AACF,GAPD,MAOO,IAAIU,MAAM,CAACG,GAAX,EAAgB;AACrB,QAAIH,MAAM,CAACE,OAAX,EAAoB;AAClB,YAAM,IAAIZ,KAAJ,CAAU,iDAAV,CAAN;AACD;;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,EAAEA,QAAQ,CAAC0B,MAAT,CACPjB,OAAD,IACEuB,KAAK,IAAIvB,OAAO,CAACwB,QAAjB,KACC,CAACxB,OAAO,CAACyB,UAAT,IAAuBzB,OAAO,CAACyB,UAAR,CAAmBF,KAAnB,EAA0BxB,GAA1B,CADxB,CAFM,CADL;AAMLP,MAAAA;AANK,KAAP;AAQD,GAfD;AAgBD;;AC5HD;AACA;AACA;AACA;;AACO,SAASkC,qBAAT,CACLC,MAAc,GAAG,IAAIC,MAAJ,CACf,mCADe,EAEf,iBAFe,CADZ,EAKC;AACNC,EAAAA,OAAO,CAACC,EAAR,CAAW,mBAAX,EAAiCC,KAAD,IAAW;AACzCJ,IAAAA,MAAM,CAACI,KAAP,CAAa,mBAAb,EAAkC;AAAEA,MAAAA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAlC;AACD,GAFD;AAGAH,EAAAA,OAAO,CAACC,EAAR,CAAW,oBAAX,EAAkCC,KAAD,IAAW;AAC1CJ,IAAAA,MAAM,CAACI,KAAP,CAAa,oBAAb,EAAmC;AAAEA,MAAAA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAnC;AACD,GAFD;AAGD;;;;"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,GAAE,MAGP,GACA,IAAI,CAON"}
|
package/rollup.config.mjs
DELETED
|
File without changes
|
|
File without changes
|