nightingale 12.1.3 → 13.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 +34 -0
- package/README.md +4 -0
- package/dist/{config.d.ts → definitions/config.d.ts} +0 -0
- package/dist/definitions/config.d.ts.map +1 -0
- package/dist/{index.d.ts → definitions/index.d.ts} +0 -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 +18 -43
- package/dist/index-browser.es.js.map +1 -1
- package/dist/index-browsermodern.es.js +16 -38
- package/dist/index-browsermodern.es.js.map +1 -1
- package/dist/{index-node14.mjs → index-node16.mjs} +17 -39
- package/dist/index-node16.mjs.map +1 -0
- package/package.json +27 -44
- package/src/config.ts +21 -15
- package/dist/config.d.ts.map +0 -1
- package/dist/index-browser.cjs.js +0 -163
- package/dist/index-browser.cjs.js.map +0 -1
- package/dist/index-node14.cjs.js +0 -150
- package/dist/index-node14.cjs.js.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/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,40 @@
|
|
|
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
|
+
# [13.0.0](https://github.com/christophehurpeau/nightingale/compare/v12.1.4...v13.0.0) (2022-11-19)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Code Refactoring
|
|
10
|
+
|
|
11
|
+
* drop node 14 and cjs ([9a8ca06](https://github.com/christophehurpeau/nightingale/commit/9a8ca064449ddc0d69e26543e21c2d522536c50a))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* build for node 16 ([30ae3e9](https://github.com/christophehurpeau/nightingale/commit/30ae3e9c455dbad793c2f704b9d860069dc80c32))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### BREAKING CHANGES
|
|
20
|
+
|
|
21
|
+
* dropped node 14 and cjs
|
|
22
|
+
* drop node 14
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## [12.1.4](https://github.com/christophehurpeau/nightingale/compare/v12.1.3...v12.1.4) (2022-02-05)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
### Bug Fixes
|
|
32
|
+
|
|
33
|
+
* better browser support when global is not defined ([194c252](https://github.com/christophehurpeau/nightingale/commit/194c25226d5aa8e7eda7cbdb899c921341f82d71))
|
|
34
|
+
* cjs build ([2e24ac5](https://github.com/christophehurpeau/nightingale/commit/2e24ac5753ee386c5be9ca56796194ee598f10ff))
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
6
40
|
## [12.1.3](https://github.com/christophehurpeau/nightingale/compare/v12.1.2...v12.1.3) (2022-01-15)
|
|
7
41
|
|
|
8
42
|
**Note:** Version bump only for package nightingale
|
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
|
|
File without changes
|
|
@@ -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;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"}
|
|
File without changes
|
|
@@ -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
|
@@ -2,29 +2,26 @@ import { Logger } from 'nightingale-logger';
|
|
|
2
2
|
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
|
+
if (process.env.NODE_ENV !== "production" && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
6
7
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
global.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
9
|
+
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
10
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
11
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
12
|
+
globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
13
13
|
handlers: [],
|
|
14
14
|
processors: []
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
|
|
18
17
|
function clearCache() {
|
|
19
|
-
|
|
18
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
20
19
|
}
|
|
21
|
-
|
|
22
20
|
function handleConfig(config) {
|
|
23
21
|
if (config.keys) {
|
|
24
22
|
if (config.pattern) {
|
|
25
23
|
throw new Error('Cannot have key and pattern for the same config');
|
|
26
24
|
}
|
|
27
|
-
|
|
28
25
|
if (config.key) {
|
|
29
26
|
throw new Error('Cannot have key and keys for the same config');
|
|
30
27
|
}
|
|
@@ -32,53 +29,41 @@ function handleConfig(config) {
|
|
|
32
29
|
if (config.pattern) {
|
|
33
30
|
throw new Error('Cannot have key and pattern for the same config');
|
|
34
31
|
}
|
|
35
|
-
|
|
36
32
|
config.keys = [config.key];
|
|
37
33
|
delete config.key;
|
|
38
34
|
}
|
|
39
|
-
|
|
40
35
|
if (config.handler) {
|
|
41
36
|
if (config.handlers) {
|
|
42
37
|
throw new Error('Cannot have handler and handlers for the same config');
|
|
43
38
|
}
|
|
44
|
-
|
|
45
39
|
config.handlers = [config.handler];
|
|
46
40
|
delete config.handler;
|
|
47
41
|
}
|
|
48
|
-
|
|
49
42
|
if (config.processor) {
|
|
50
43
|
if (config.processors) {
|
|
51
44
|
throw new Error('Cannot have processors and processors for the same config');
|
|
52
45
|
}
|
|
53
|
-
|
|
54
46
|
config.processors = [config.processor];
|
|
55
47
|
delete config.processor;
|
|
56
48
|
}
|
|
57
|
-
|
|
58
49
|
return config;
|
|
59
50
|
}
|
|
60
|
-
|
|
61
51
|
function configure(config) {
|
|
62
|
-
if (
|
|
52
|
+
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
63
53
|
// eslint-disable-next-line no-console
|
|
64
54
|
console.log('nightingale: warning: config overridden');
|
|
65
55
|
}
|
|
66
|
-
|
|
67
56
|
clearCache();
|
|
68
|
-
|
|
57
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
69
58
|
}
|
|
70
59
|
function addConfig(config, unshift) {
|
|
71
60
|
if (unshift === void 0) {
|
|
72
61
|
unshift = false;
|
|
73
62
|
}
|
|
74
|
-
|
|
75
63
|
config = handleConfig(config);
|
|
76
|
-
|
|
77
|
-
global.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
78
|
-
|
|
64
|
+
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
79
65
|
clearCache();
|
|
80
66
|
}
|
|
81
|
-
|
|
82
67
|
var configIsForKey = function configIsForKey(key) {
|
|
83
68
|
return function (config) {
|
|
84
69
|
if (config.keys) return config.keys.includes(key);
|
|
@@ -86,38 +71,30 @@ var configIsForKey = function configIsForKey(key) {
|
|
|
86
71
|
return true;
|
|
87
72
|
};
|
|
88
73
|
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
var globalCache = global.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
74
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = function (key) {
|
|
75
|
+
var globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
92
76
|
var existingCache = globalCache.get(key);
|
|
93
|
-
|
|
94
77
|
if (existingCache) {
|
|
95
78
|
return existingCache;
|
|
96
79
|
}
|
|
97
|
-
|
|
98
80
|
var loggerConfig = {
|
|
99
81
|
handlers: [],
|
|
100
82
|
processors: []
|
|
101
83
|
};
|
|
102
|
-
|
|
103
|
-
global.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(function (config) {
|
|
84
|
+
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(function (config) {
|
|
104
85
|
var _loggerConfig$handler, _loggerConfig$process;
|
|
105
|
-
|
|
106
86
|
if (config.handlers) (_loggerConfig$handler = loggerConfig.handlers).push.apply(_loggerConfig$handler, config.handlers);
|
|
107
87
|
if (config.processors) (_loggerConfig$process = loggerConfig.processors).push.apply(_loggerConfig$process, config.processors);
|
|
108
88
|
return config.stop;
|
|
109
89
|
});
|
|
110
|
-
|
|
111
90
|
globalCache.set(key, loggerConfig);
|
|
112
91
|
return loggerConfig;
|
|
113
92
|
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
processors = _global$__NIGHTINGALE.processors;
|
|
120
|
-
|
|
93
|
+
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
94
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = function (key, level) {
|
|
95
|
+
var _globalOrWindow$__NIG = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key),
|
|
96
|
+
handlers = _globalOrWindow$__NIG.handlers,
|
|
97
|
+
processors = _globalOrWindow$__NIG.processors;
|
|
121
98
|
return {
|
|
122
99
|
handlers: handlers.filter(function (handler) {
|
|
123
100
|
return level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key));
|
|
@@ -131,12 +108,10 @@ if (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
|
131
108
|
* listen to uncaughtException and unhandledRejection
|
|
132
109
|
* @param {Logger} [logger]
|
|
133
110
|
*/
|
|
134
|
-
|
|
135
111
|
function listenUnhandledErrors(logger) {
|
|
136
112
|
if (logger === void 0) {
|
|
137
113
|
logger = new Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors');
|
|
138
114
|
}
|
|
139
|
-
|
|
140
115
|
process.on('uncaughtException', function (error) {
|
|
141
116
|
logger.error('uncaughtException', {
|
|
142
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\nif (__DEV__ &&
|
|
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 (__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","__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,MAAM,KAAK,WAAW,GAAGA,MAAM,GAAIC,MAAwB,CAAA;AAEpE,IAAI,OAAWF,CAAAA,GAAAA,CAAAA,QAAAA,KAAAA,YAAAA,IAAAA,cAAc,CAACG,6BAA6B,EAAE;AAC3D,EAAA,MAAM,IAAIC,KAAK,CAAC,mCAAmC,CAAC,CAAA;AACtD,CAAA;AAEA,IAAI,CAACJ,cAAc,CAACK,oBAAoB,EAAE;EACxCL,cAAc,CAACK,oBAAoB,GAAG,EAAE,CAAA;AACxCL,EAAAA,cAAc,CAACM,8BAA8B,GAAG,IAAIC,GAAG,EAGpD,CAAA;EACHP,cAAc,CAACQ,4BAA4B,GAAG;AAC5CC,IAAAA,QAAQ,EAAE,EAAE;AACZC,IAAAA,UAAU,EAAE,EAAA;GACb,CAAA;AACH,CAA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AIvB,OAAO,CAACwB,QAAQ,KACxB,CAACxB,OAAO,CAACyB,UAAU,IAAIzB,OAAO,CAACyB,UAAU,CAACF,KAAK,EAAExB,GAAG,CAAC,CAAC,CAAA;OAC1D,CAAA;AACDP,MAAAA,UAAU,EAAVA,UAAAA;KACD,CAAA;GACF,CAAA;AACH;;AC5HA;AACA;AACA;AACA;AACO,SAASkC,qBAAqB,CACnCC,MAAc,EAIR;AAAA,EAAA,IAJNA,MAAc,KAAA,KAAA,CAAA,EAAA;AAAdA,IAAAA,MAAc,GAAG,IAAIC,MAAM,CACzB,mCAAmC,EACnC,iBAAiB,CAClB,CAAA;AAAA,GAAA;AAEDC,EAAAA,OAAO,CAACC,EAAE,CAAC,mBAAmB,EAAE,UAACC,KAAK,EAAK;AACzCJ,IAAAA,MAAM,CAACI,KAAK,CAAC,mBAAmB,EAAE;AAAEA,MAAAA,KAAK,EAALA,KAAK;AAAEC,MAAAA,SAAS,EAAE,IAAA;AAAK,KAAC,CAAC,CAAA;AAC/D,GAAC,CAAC,CAAA;AACFH,EAAAA,OAAO,CAACC,EAAE,CAAC,oBAAoB,EAAE,UAACC,KAAK,EAAK;AAC1CJ,IAAAA,MAAM,CAACI,KAAK,CAAC,oBAAoB,EAAE;AAAEA,MAAAA,KAAK,EAALA,KAAK;AAAEC,MAAAA,SAAS,EAAE,IAAA;AAAK,KAAC,CAAC,CAAA;AAChE,GAAC,CAAC,CAAA;AACJ;;;;"}
|
|
@@ -2,29 +2,26 @@ import { Logger } from 'nightingale-logger';
|
|
|
2
2
|
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
|
+
if (process.env.NODE_ENV !== "production" && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
6
7
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
global.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
9
|
+
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
10
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
11
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
12
|
+
globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
13
13
|
handlers: [],
|
|
14
14
|
processors: []
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
|
|
18
17
|
function clearCache() {
|
|
19
|
-
|
|
18
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
20
19
|
}
|
|
21
|
-
|
|
22
20
|
function handleConfig(config) {
|
|
23
21
|
if (config.keys) {
|
|
24
22
|
if (config.pattern) {
|
|
25
23
|
throw new Error('Cannot have key and pattern for the same config');
|
|
26
24
|
}
|
|
27
|
-
|
|
28
25
|
if (config.key) {
|
|
29
26
|
throw new Error('Cannot have key and keys for the same config');
|
|
30
27
|
}
|
|
@@ -32,85 +29,67 @@ function handleConfig(config) {
|
|
|
32
29
|
if (config.pattern) {
|
|
33
30
|
throw new Error('Cannot have key and pattern for the same config');
|
|
34
31
|
}
|
|
35
|
-
|
|
36
32
|
config.keys = [config.key];
|
|
37
33
|
delete config.key;
|
|
38
34
|
}
|
|
39
|
-
|
|
40
35
|
if (config.handler) {
|
|
41
36
|
if (config.handlers) {
|
|
42
37
|
throw new Error('Cannot have handler and handlers for the same config');
|
|
43
38
|
}
|
|
44
|
-
|
|
45
39
|
config.handlers = [config.handler];
|
|
46
40
|
delete config.handler;
|
|
47
41
|
}
|
|
48
|
-
|
|
49
42
|
if (config.processor) {
|
|
50
43
|
if (config.processors) {
|
|
51
44
|
throw new Error('Cannot have processors and processors for the same config');
|
|
52
45
|
}
|
|
53
|
-
|
|
54
46
|
config.processors = [config.processor];
|
|
55
47
|
delete config.processor;
|
|
56
48
|
}
|
|
57
|
-
|
|
58
49
|
return config;
|
|
59
50
|
}
|
|
60
|
-
|
|
61
51
|
function configure(config) {
|
|
62
|
-
if (
|
|
52
|
+
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
63
53
|
// eslint-disable-next-line no-console
|
|
64
54
|
console.log('nightingale: warning: config overridden');
|
|
65
55
|
}
|
|
66
|
-
|
|
67
56
|
clearCache();
|
|
68
|
-
|
|
57
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
69
58
|
}
|
|
70
59
|
function addConfig(config, unshift = false) {
|
|
71
60
|
config = handleConfig(config);
|
|
72
|
-
|
|
73
|
-
global.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
74
|
-
|
|
61
|
+
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
75
62
|
clearCache();
|
|
76
63
|
}
|
|
77
|
-
|
|
78
64
|
const configIsForKey = key => config => {
|
|
79
65
|
if (config.keys) return config.keys.includes(key);
|
|
80
66
|
if (config.pattern) return config.pattern.test(key);
|
|
81
67
|
return true;
|
|
82
68
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const globalCache = global.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
69
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
70
|
+
const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
86
71
|
const existingCache = globalCache.get(key);
|
|
87
|
-
|
|
88
72
|
if (existingCache) {
|
|
89
73
|
return existingCache;
|
|
90
74
|
}
|
|
91
|
-
|
|
92
75
|
const loggerConfig = {
|
|
93
76
|
handlers: [],
|
|
94
77
|
processors: []
|
|
95
78
|
};
|
|
96
|
-
|
|
97
|
-
global.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
|
|
79
|
+
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
|
|
98
80
|
if (config.handlers) loggerConfig.handlers.push(...config.handlers);
|
|
99
81
|
if (config.processors) loggerConfig.processors.push(...config.processors);
|
|
100
82
|
return config.stop;
|
|
101
83
|
});
|
|
102
|
-
|
|
103
84
|
globalCache.set(key, loggerConfig);
|
|
104
85
|
return loggerConfig;
|
|
105
86
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
|
|
87
|
+
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
88
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
|
|
109
89
|
const {
|
|
110
90
|
handlers,
|
|
111
91
|
processors
|
|
112
|
-
} =
|
|
113
|
-
|
|
92
|
+
} = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
|
|
114
93
|
return {
|
|
115
94
|
handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
|
|
116
95
|
processors
|
|
@@ -122,7 +101,6 @@ if (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
|
122
101
|
* listen to uncaughtException and unhandledRejection
|
|
123
102
|
* @param {Logger} [logger]
|
|
124
103
|
*/
|
|
125
|
-
|
|
126
104
|
function listenUnhandledErrors(logger = new Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
|
|
127
105
|
process.on('uncaughtException', error => {
|
|
128
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\nif (__DEV__ &&
|
|
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 (__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","__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,MAAM,KAAK,WAAW,GAAGA,MAAM,GAAIC,MAAwB,CAAA;AAEpE,IAAI,OAAWF,CAAAA,GAAAA,CAAAA,QAAAA,KAAAA,YAAAA,IAAAA,cAAc,CAACG,6BAA6B,EAAE;AAC3D,EAAA,MAAM,IAAIC,KAAK,CAAC,mCAAmC,CAAC,CAAA;AACtD,CAAA;AAEA,IAAI,CAACJ,cAAc,CAACK,oBAAoB,EAAE;EACxCL,cAAc,CAACK,oBAAoB,GAAG,EAAE,CAAA;AACxCL,EAAAA,cAAc,CAACM,8BAA8B,GAAG,IAAIC,GAAG,EAGpD,CAAA;EACHP,cAAc,CAACQ,4BAA4B,GAAG;AAC5CC,IAAAA,QAAQ,EAAE,EAAE;AACZC,IAAAA,UAAU,EAAE,EAAA;GACb,CAAA;AACH,CAAA;AAEA,SAASC,UAAU,GAAS;AAC1BX,EAAAA,cAAc,CAACM,8BAA8B,CAACM,KAAK,EAAE,CAAA;AACvD,CAAA;AAEA,SAASC,YAAY,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,8CAA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,IAAA;AAAK,KAAC,CAAC,CAAA;AAChE,GAAC,CAAC,CAAA;AACJ;;;;"}
|
|
@@ -2,29 +2,26 @@ import { Logger } from 'nightingale-logger';
|
|
|
2
2
|
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
|
+
if (process.env.NODE_ENV !== "production" && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
6
7
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
global.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
9
|
+
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
10
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
11
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
12
|
+
globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
13
13
|
handlers: [],
|
|
14
14
|
processors: []
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
|
|
18
17
|
function clearCache() {
|
|
19
|
-
|
|
18
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
20
19
|
}
|
|
21
|
-
|
|
22
20
|
function handleConfig(config) {
|
|
23
21
|
if (config.keys) {
|
|
24
22
|
if (config.pattern) {
|
|
25
23
|
throw new Error('Cannot have key and pattern for the same config');
|
|
26
24
|
}
|
|
27
|
-
|
|
28
25
|
if (config.key) {
|
|
29
26
|
throw new Error('Cannot have key and keys for the same config');
|
|
30
27
|
}
|
|
@@ -32,85 +29,67 @@ function handleConfig(config) {
|
|
|
32
29
|
if (config.pattern) {
|
|
33
30
|
throw new Error('Cannot have key and pattern for the same config');
|
|
34
31
|
}
|
|
35
|
-
|
|
36
32
|
config.keys = [config.key];
|
|
37
33
|
delete config.key;
|
|
38
34
|
}
|
|
39
|
-
|
|
40
35
|
if (config.handler) {
|
|
41
36
|
if (config.handlers) {
|
|
42
37
|
throw new Error('Cannot have handler and handlers for the same config');
|
|
43
38
|
}
|
|
44
|
-
|
|
45
39
|
config.handlers = [config.handler];
|
|
46
40
|
delete config.handler;
|
|
47
41
|
}
|
|
48
|
-
|
|
49
42
|
if (config.processor) {
|
|
50
43
|
if (config.processors) {
|
|
51
44
|
throw new Error('Cannot have processors and processors for the same config');
|
|
52
45
|
}
|
|
53
|
-
|
|
54
46
|
config.processors = [config.processor];
|
|
55
47
|
delete config.processor;
|
|
56
48
|
}
|
|
57
|
-
|
|
58
49
|
return config;
|
|
59
50
|
}
|
|
60
|
-
|
|
61
51
|
function configure(config) {
|
|
62
|
-
if (
|
|
52
|
+
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
63
53
|
// eslint-disable-next-line no-console
|
|
64
54
|
console.log('nightingale: warning: config overridden');
|
|
65
55
|
}
|
|
66
|
-
|
|
67
56
|
clearCache();
|
|
68
|
-
|
|
57
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
69
58
|
}
|
|
70
59
|
function addConfig(config, unshift = false) {
|
|
71
60
|
config = handleConfig(config);
|
|
72
|
-
|
|
73
|
-
global.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
74
|
-
|
|
61
|
+
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
75
62
|
clearCache();
|
|
76
63
|
}
|
|
77
|
-
|
|
78
64
|
const configIsForKey = key => config => {
|
|
79
65
|
if (config.keys) return config.keys.includes(key);
|
|
80
66
|
if (config.pattern) return config.pattern.test(key);
|
|
81
67
|
return true;
|
|
82
68
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const globalCache = global.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
69
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
70
|
+
const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
86
71
|
const existingCache = globalCache.get(key);
|
|
87
|
-
|
|
88
72
|
if (existingCache) {
|
|
89
73
|
return existingCache;
|
|
90
74
|
}
|
|
91
|
-
|
|
92
75
|
const loggerConfig = {
|
|
93
76
|
handlers: [],
|
|
94
77
|
processors: []
|
|
95
78
|
};
|
|
96
|
-
|
|
97
|
-
global.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
|
|
79
|
+
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
|
|
98
80
|
if (config.handlers) loggerConfig.handlers.push(...config.handlers);
|
|
99
81
|
if (config.processors) loggerConfig.processors.push(...config.processors);
|
|
100
82
|
return config.stop;
|
|
101
83
|
});
|
|
102
|
-
|
|
103
84
|
globalCache.set(key, loggerConfig);
|
|
104
85
|
return loggerConfig;
|
|
105
86
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
|
|
87
|
+
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
88
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
|
|
109
89
|
const {
|
|
110
90
|
handlers,
|
|
111
91
|
processors
|
|
112
|
-
} =
|
|
113
|
-
|
|
92
|
+
} = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
|
|
114
93
|
return {
|
|
115
94
|
handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
|
|
116
95
|
processors
|
|
@@ -122,7 +101,6 @@ if (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
|
122
101
|
* listen to uncaughtException and unhandledRejection
|
|
123
102
|
* @param {Logger} [logger]
|
|
124
103
|
*/
|
|
125
|
-
|
|
126
104
|
function listenUnhandledErrors(logger = new Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
|
|
127
105
|
process.on('uncaughtException', error => {
|
|
128
106
|
logger.error('uncaughtException', {
|
|
@@ -139,4 +117,4 @@ function listenUnhandledErrors(logger = new Logger('nightingale:listenUnhandledE
|
|
|
139
117
|
}
|
|
140
118
|
|
|
141
119
|
export { addConfig, configure, listenUnhandledErrors };
|
|
142
|
-
//# sourceMappingURL=index-
|
|
120
|
+
//# sourceMappingURL=index-node16.mjs.map
|