nightingale 12.1.3 → 12.1.4
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 +12 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/index-browser.cjs.js +19 -17
- package/dist/index-browser.cjs.js.map +1 -1
- package/dist/index-browser.es.js +19 -17
- package/dist/index-browser.es.js.map +1 -1
- package/dist/index-browsermodern.es.js +17 -15
- package/dist/index-browsermodern.es.js.map +1 -1
- package/dist/{index-node14.cjs.js → index-node14.cjs} +18 -16
- package/dist/index-node14.cjs.map +1 -0
- package/dist/index-node14.mjs +17 -15
- package/dist/index-node14.mjs.map +1 -1
- package/package.json +11 -11
- package/src/config.ts +21 -15
- package/dist/index-node14.cjs.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
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
|
+
## [12.1.4](https://github.com/christophehurpeau/nightingale/compare/v12.1.3...v12.1.4) (2022-02-05)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* better browser support when global is not defined ([194c252](https://github.com/christophehurpeau/nightingale/commit/194c25226d5aa8e7eda7cbdb899c921341f82d71))
|
|
12
|
+
* cjs build ([2e24ac5](https://github.com/christophehurpeau/nightingale/commit/2e24ac5753ee386c5be9ca56796194ee598f10ff))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
6
18
|
## [12.1.3](https://github.com/christophehurpeau/nightingale/compare/v12.1.2...v12.1.3) (2022-01-15)
|
|
7
19
|
|
|
8
20
|
**Note:** Version bump only for package nightingale
|
package/dist/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwB,MAAM,EAAE,MAAM,oBAAoB,CAAC;
|
|
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"}
|
|
@@ -5,21 +5,23 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var nightingaleLogger = require('nightingale-logger');
|
|
6
6
|
var nightingaleLevels = require('nightingale-levels');
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
var globalOrWindow = typeof global !== 'undefined' ? global : window;
|
|
9
|
+
|
|
10
|
+
if ((process.env.NODE_ENV !== "production") && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
9
11
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
if (!
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
15
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
16
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
17
|
+
globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
16
18
|
handlers: [],
|
|
17
19
|
processors: []
|
|
18
20
|
};
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
function clearCache() {
|
|
22
|
-
|
|
24
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
function handleConfig(config) {
|
|
@@ -62,13 +64,13 @@ function handleConfig(config) {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
function configure(config) {
|
|
65
|
-
if (
|
|
67
|
+
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
66
68
|
// eslint-disable-next-line no-console
|
|
67
69
|
console.log('nightingale: warning: config overridden');
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
clearCache();
|
|
71
|
-
|
|
73
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
72
74
|
}
|
|
73
75
|
function addConfig(config, unshift) {
|
|
74
76
|
if (unshift === void 0) {
|
|
@@ -77,7 +79,7 @@ function addConfig(config, unshift) {
|
|
|
77
79
|
|
|
78
80
|
config = handleConfig(config);
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
81
83
|
|
|
82
84
|
clearCache();
|
|
83
85
|
}
|
|
@@ -90,8 +92,8 @@ var configIsForKey = function configIsForKey(key) {
|
|
|
90
92
|
};
|
|
91
93
|
};
|
|
92
94
|
|
|
93
|
-
|
|
94
|
-
var globalCache =
|
|
95
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = function (key) {
|
|
96
|
+
var globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
95
97
|
var existingCache = globalCache.get(key);
|
|
96
98
|
|
|
97
99
|
if (existingCache) {
|
|
@@ -103,7 +105,7 @@ global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = function (key) {
|
|
|
103
105
|
processors: []
|
|
104
106
|
};
|
|
105
107
|
|
|
106
|
-
|
|
108
|
+
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(function (config) {
|
|
107
109
|
var _loggerConfig$handler, _loggerConfig$process;
|
|
108
110
|
|
|
109
111
|
if (config.handlers) (_loggerConfig$handler = loggerConfig.handlers).push.apply(_loggerConfig$handler, config.handlers);
|
|
@@ -115,11 +117,11 @@ global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = function (key) {
|
|
|
115
117
|
return loggerConfig;
|
|
116
118
|
};
|
|
117
119
|
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
var
|
|
121
|
-
handlers =
|
|
122
|
-
processors =
|
|
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;
|
|
123
125
|
|
|
124
126
|
return {
|
|
125
127
|
handlers: handlers.filter(function (handler) {
|
|
@@ -1 +1 @@
|
|
|
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\nif (__DEV__ &&
|
|
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,C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P;AAQD,GAfD;AAgBD;;AC5HD;AACA;AACA;AACA;;AACO,SAASkC,qBAAT,CACLC,MADK,EAKC;AAAA,MAJNA,MAIM;AAJNA,IAAAA,MAIM,GAJW,IAAIC,wBAAJ,CACf,mCADe,EAEf,iBAFe,CAIX;AAAA;;AACNC,EAAAA,OAAO,CAACC,EAAR,CAAW,mBAAX,EAAgC,UAACC,KAAD,EAAW;AACzCJ,IAAAA,MAAM,CAACI,KAAP,CAAa,mBAAb,EAAkC;AAAEA,MAAAA,KAAK,EAALA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAlC;AACD,GAFD;AAGAH,EAAAA,OAAO,CAACC,EAAR,CAAW,oBAAX,EAAiC,UAACC,KAAD,EAAW;AAC1CJ,IAAAA,MAAM,CAACI,KAAP,CAAa,oBAAb,EAAmC;AAAEA,MAAAA,KAAK,EAALA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAnC;AACD,GAFD;AAGD;;;;;;;;;"}
|
package/dist/index-browser.es.js
CHANGED
|
@@ -2,21 +2,23 @@ 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
|
+
|
|
7
|
+
if ((process.env.NODE_ENV !== "production") && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
6
8
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
if (!
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
12
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
13
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
14
|
+
globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
13
15
|
handlers: [],
|
|
14
16
|
processors: []
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
function clearCache() {
|
|
19
|
-
|
|
21
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
function handleConfig(config) {
|
|
@@ -59,13 +61,13 @@ function handleConfig(config) {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
function configure(config) {
|
|
62
|
-
if (
|
|
64
|
+
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
63
65
|
// eslint-disable-next-line no-console
|
|
64
66
|
console.log('nightingale: warning: config overridden');
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
clearCache();
|
|
68
|
-
|
|
70
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
69
71
|
}
|
|
70
72
|
function addConfig(config, unshift) {
|
|
71
73
|
if (unshift === void 0) {
|
|
@@ -74,7 +76,7 @@ function addConfig(config, unshift) {
|
|
|
74
76
|
|
|
75
77
|
config = handleConfig(config);
|
|
76
78
|
|
|
77
|
-
|
|
79
|
+
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
78
80
|
|
|
79
81
|
clearCache();
|
|
80
82
|
}
|
|
@@ -87,8 +89,8 @@ var configIsForKey = function configIsForKey(key) {
|
|
|
87
89
|
};
|
|
88
90
|
};
|
|
89
91
|
|
|
90
|
-
|
|
91
|
-
var globalCache =
|
|
92
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = function (key) {
|
|
93
|
+
var globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
92
94
|
var existingCache = globalCache.get(key);
|
|
93
95
|
|
|
94
96
|
if (existingCache) {
|
|
@@ -100,7 +102,7 @@ global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = function (key) {
|
|
|
100
102
|
processors: []
|
|
101
103
|
};
|
|
102
104
|
|
|
103
|
-
|
|
105
|
+
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(function (config) {
|
|
104
106
|
var _loggerConfig$handler, _loggerConfig$process;
|
|
105
107
|
|
|
106
108
|
if (config.handlers) (_loggerConfig$handler = loggerConfig.handlers).push.apply(_loggerConfig$handler, config.handlers);
|
|
@@ -112,11 +114,11 @@ global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = function (key) {
|
|
|
112
114
|
return loggerConfig;
|
|
113
115
|
};
|
|
114
116
|
|
|
115
|
-
if (
|
|
116
|
-
|
|
117
|
-
var
|
|
118
|
-
handlers =
|
|
119
|
-
processors =
|
|
117
|
+
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
118
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = function (key, level) {
|
|
119
|
+
var _globalOrWindow$__NIG = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key),
|
|
120
|
+
handlers = _globalOrWindow$__NIG.handlers,
|
|
121
|
+
processors = _globalOrWindow$__NIG.processors;
|
|
120
122
|
|
|
121
123
|
return {
|
|
122
124
|
handlers: handlers.filter(function (handler) {
|
|
@@ -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","__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,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;;AACDU,IAAAA,MAAM,CAACC,IAAP,GAAc,CAACD,MAAM,CAACG,GAAR,CAAd;AACA,WAAOH,MAAM,CAACG,GAAd;AACD;;AAED,MAAIH,MAAM,CAACI,OAAX,EAAoB;AACl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,QAAQ,EAAEA,QAAQ,CAAC0B,MAAT,CACR,UAACjB,OAAD;AAAA,eACEuB,KAAK,IAAIvB,OAAO,CAACwB,QAAjB,KACC,CAACxB,OAAO,CAACyB,UAAT,IAAuBzB,OAAO,CAACyB,UAAR,CAAmBF,KAAnB,EAA0BxB,GAA1B,CADxB,CADF;AAAA,OADQ,CADL;AAMLP,MAAAA,UAAU,EAAVA;AANK,KAAP;AAQD,GAfD;AAgBD;;AC5HD;AACA;AACA;AACA;;AACO,SAASkC,qBAAT,CACLC,MADK,EAKC;AAAA,MAJNA,MAIM;AAJNA,IAAAA,MAIM,GAJW,IAAIC,MAAJ,CACf,mCADe,EAEf,iBAFe,CAIX;AAAA;;AACNC,EAAAA,OAAO,CAACC,EAAR,CAAW,mBAAX,EAAgC,UAACC,KAAD,EAAW;AACzCJ,IAAAA,MAAM,CAACI,KAAP,CAAa,mBAAb,EAAkC;AAAEA,MAAAA,KAAK,EAALA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAlC;AACD,GAFD;AAGAH,EAAAA,OAAO,CAACC,EAAR,CAAW,oBAAX,EAAiC,UAACC,KAAD,EAAW;AAC1CJ,IAAAA,MAAM,CAACI,KAAP,CAAa,oBAAb,EAAmC;AAAEA,MAAAA,KAAK,EAALA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAnC;AACD,GAFD;AAGD;;;;"}
|
|
@@ -2,21 +2,23 @@ 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
|
+
|
|
7
|
+
if ((process.env.NODE_ENV !== "production") && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
6
8
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
if (!
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
12
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
13
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
14
|
+
globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
13
15
|
handlers: [],
|
|
14
16
|
processors: []
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
function clearCache() {
|
|
19
|
-
|
|
21
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
function handleConfig(config) {
|
|
@@ -59,18 +61,18 @@ function handleConfig(config) {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
function configure(config) {
|
|
62
|
-
if (
|
|
64
|
+
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
63
65
|
// eslint-disable-next-line no-console
|
|
64
66
|
console.log('nightingale: warning: config overridden');
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
clearCache();
|
|
68
|
-
|
|
70
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
69
71
|
}
|
|
70
72
|
function addConfig(config, unshift = false) {
|
|
71
73
|
config = handleConfig(config);
|
|
72
74
|
|
|
73
|
-
|
|
75
|
+
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
74
76
|
|
|
75
77
|
clearCache();
|
|
76
78
|
}
|
|
@@ -81,8 +83,8 @@ const configIsForKey = key => config => {
|
|
|
81
83
|
return true;
|
|
82
84
|
};
|
|
83
85
|
|
|
84
|
-
|
|
85
|
-
const globalCache =
|
|
86
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
87
|
+
const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
86
88
|
const existingCache = globalCache.get(key);
|
|
87
89
|
|
|
88
90
|
if (existingCache) {
|
|
@@ -94,7 +96,7 @@ global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
|
94
96
|
processors: []
|
|
95
97
|
};
|
|
96
98
|
|
|
97
|
-
|
|
99
|
+
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
|
|
98
100
|
if (config.handlers) loggerConfig.handlers.push(...config.handlers);
|
|
99
101
|
if (config.processors) loggerConfig.processors.push(...config.processors);
|
|
100
102
|
return config.stop;
|
|
@@ -104,12 +106,12 @@ global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
|
104
106
|
return loggerConfig;
|
|
105
107
|
};
|
|
106
108
|
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
+
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
110
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
|
|
109
111
|
const {
|
|
110
112
|
handlers,
|
|
111
113
|
processors
|
|
112
|
-
} =
|
|
114
|
+
} = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
|
|
113
115
|
|
|
114
116
|
return {
|
|
115
117
|
handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
|
|
@@ -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","__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;;AACDU,IAAAA,MAAM,CAACC,IAAP,GAAc,CAACD,MAAM,CAACG,GAAR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IvB,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;;;;"}
|
|
@@ -5,21 +5,23 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
const nightingaleLogger = require('nightingale-logger');
|
|
6
6
|
const nightingaleLevels = require('nightingale-levels');
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const globalOrWindow = typeof global !== 'undefined' ? global : window;
|
|
9
|
+
|
|
10
|
+
if ((process.env.NODE_ENV !== "production") && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
9
11
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
if (!
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
15
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
16
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
17
|
+
globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
16
18
|
handlers: [],
|
|
17
19
|
processors: []
|
|
18
20
|
};
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
function clearCache() {
|
|
22
|
-
|
|
24
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
function handleConfig(config) {
|
|
@@ -62,18 +64,18 @@ function handleConfig(config) {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
function configure(config) {
|
|
65
|
-
if (
|
|
67
|
+
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
66
68
|
// eslint-disable-next-line no-console
|
|
67
69
|
console.log('nightingale: warning: config overridden');
|
|
68
70
|
}
|
|
69
71
|
|
|
70
72
|
clearCache();
|
|
71
|
-
|
|
73
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
72
74
|
}
|
|
73
75
|
function addConfig(config, unshift = false) {
|
|
74
76
|
config = handleConfig(config);
|
|
75
77
|
|
|
76
|
-
|
|
78
|
+
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
77
79
|
|
|
78
80
|
clearCache();
|
|
79
81
|
}
|
|
@@ -84,8 +86,8 @@ const configIsForKey = key => config => {
|
|
|
84
86
|
return true;
|
|
85
87
|
};
|
|
86
88
|
|
|
87
|
-
|
|
88
|
-
const globalCache =
|
|
89
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
90
|
+
const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
89
91
|
const existingCache = globalCache.get(key);
|
|
90
92
|
|
|
91
93
|
if (existingCache) {
|
|
@@ -97,7 +99,7 @@ global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
|
97
99
|
processors: []
|
|
98
100
|
};
|
|
99
101
|
|
|
100
|
-
|
|
102
|
+
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
|
|
101
103
|
if (config.handlers) loggerConfig.handlers.push(...config.handlers);
|
|
102
104
|
if (config.processors) loggerConfig.processors.push(...config.processors);
|
|
103
105
|
return config.stop;
|
|
@@ -107,12 +109,12 @@ global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
|
107
109
|
return loggerConfig;
|
|
108
110
|
};
|
|
109
111
|
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
+
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
113
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
|
|
112
114
|
const {
|
|
113
115
|
handlers,
|
|
114
116
|
processors
|
|
115
|
-
} =
|
|
117
|
+
} = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
|
|
116
118
|
|
|
117
119
|
return {
|
|
118
120
|
handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
|
|
@@ -147,4 +149,4 @@ exports.levels = nightingaleLevels.Level;
|
|
|
147
149
|
exports.addConfig = addConfig;
|
|
148
150
|
exports.configure = configure;
|
|
149
151
|
exports.listenUnhandledErrors = listenUnhandledErrors;
|
|
150
|
-
//# sourceMappingURL=index-node14.cjs.
|
|
152
|
+
//# sourceMappingURL=index-node14.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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,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;;AACDU,IAAAA,MAAM,CAACC,IAAP,GAAc,CAACD,MAAM,CAACG,GAAR,CAAd;AACA,WAAOH,MAAM,CAACG,GAAd;AACD;;AAED,MAAIH,MAAM,CAACI,OAAX,EAAoB;AAClB,QAAIJ,MAAM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,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;;;;;;;;;"}
|
package/dist/index-node14.mjs
CHANGED
|
@@ -2,21 +2,23 @@ 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
|
+
|
|
7
|
+
if ((process.env.NODE_ENV !== "production") && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
6
8
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
7
9
|
}
|
|
8
10
|
|
|
9
|
-
if (!
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
12
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
13
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
14
|
+
globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
13
15
|
handlers: [],
|
|
14
16
|
processors: []
|
|
15
17
|
};
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
function clearCache() {
|
|
19
|
-
|
|
21
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
function handleConfig(config) {
|
|
@@ -59,18 +61,18 @@ function handleConfig(config) {
|
|
|
59
61
|
}
|
|
60
62
|
|
|
61
63
|
function configure(config) {
|
|
62
|
-
if (
|
|
64
|
+
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
63
65
|
// eslint-disable-next-line no-console
|
|
64
66
|
console.log('nightingale: warning: config overridden');
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
clearCache();
|
|
68
|
-
|
|
70
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
69
71
|
}
|
|
70
72
|
function addConfig(config, unshift = false) {
|
|
71
73
|
config = handleConfig(config);
|
|
72
74
|
|
|
73
|
-
|
|
75
|
+
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
74
76
|
|
|
75
77
|
clearCache();
|
|
76
78
|
}
|
|
@@ -81,8 +83,8 @@ const configIsForKey = key => config => {
|
|
|
81
83
|
return true;
|
|
82
84
|
};
|
|
83
85
|
|
|
84
|
-
|
|
85
|
-
const globalCache =
|
|
86
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
87
|
+
const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
86
88
|
const existingCache = globalCache.get(key);
|
|
87
89
|
|
|
88
90
|
if (existingCache) {
|
|
@@ -94,7 +96,7 @@ global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
|
94
96
|
processors: []
|
|
95
97
|
};
|
|
96
98
|
|
|
97
|
-
|
|
99
|
+
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
|
|
98
100
|
if (config.handlers) loggerConfig.handlers.push(...config.handlers);
|
|
99
101
|
if (config.processors) loggerConfig.processors.push(...config.processors);
|
|
100
102
|
return config.stop;
|
|
@@ -104,12 +106,12 @@ global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
|
104
106
|
return loggerConfig;
|
|
105
107
|
};
|
|
106
108
|
|
|
107
|
-
if (
|
|
108
|
-
|
|
109
|
+
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
110
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
|
|
109
111
|
const {
|
|
110
112
|
handlers,
|
|
111
113
|
processors
|
|
112
|
-
} =
|
|
114
|
+
} = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
|
|
113
115
|
|
|
114
116
|
return {
|
|
115
117
|
handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
|
|
@@ -1 +1 @@
|
|
|
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\nif (__DEV__ &&
|
|
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,OA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f,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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nightingale",
|
|
3
|
-
"version": "12.1.
|
|
3
|
+
"version": "12.1.4",
|
|
4
4
|
"description": "Logger for browser and node",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logger"
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
".": {
|
|
34
34
|
"node": {
|
|
35
35
|
"import": "./dist/index-node14.mjs",
|
|
36
|
-
"require": "./dist/index-node14.cjs
|
|
36
|
+
"require": "./dist/index-node14.cjs"
|
|
37
37
|
},
|
|
38
38
|
"browser": {
|
|
39
39
|
"browser:modern": {
|
|
@@ -91,17 +91,17 @@
|
|
|
91
91
|
},
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"@types/node": ">=14.0.0",
|
|
94
|
-
"nightingale-levels": "12.1.
|
|
95
|
-
"nightingale-logger": "12.1.
|
|
96
|
-
"nightingale-types": "12.1.
|
|
94
|
+
"nightingale-levels": "12.1.4",
|
|
95
|
+
"nightingale-logger": "12.1.4",
|
|
96
|
+
"nightingale-types": "12.1.4"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
|
-
"@babel/core": "7.
|
|
100
|
-
"@babel/preset-env": "7.16.
|
|
99
|
+
"@babel/core": "7.17.0",
|
|
100
|
+
"@babel/preset-env": "7.16.11",
|
|
101
101
|
"babel-preset-modern-browsers": "15.0.2",
|
|
102
|
-
"nightingale-string": "12.1.
|
|
103
|
-
"pob-babel": "
|
|
104
|
-
"typescript": "4.5.
|
|
102
|
+
"nightingale-string": "12.1.4",
|
|
103
|
+
"pob-babel": "30.0.1",
|
|
104
|
+
"typescript": "4.5.5"
|
|
105
105
|
},
|
|
106
|
-
"gitHead": "
|
|
106
|
+
"gitHead": "3754d4575d948b5bb8c5227d3c3f4ca25e801db5"
|
|
107
107
|
}
|
package/src/config.ts
CHANGED
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import type { ComputedConfigForKey, Config } from 'nightingale-logger';
|
|
2
2
|
import type { Handler } from 'nightingale-types';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
const globalOrWindow: typeof global =
|
|
5
|
+
typeof global !== 'undefined' ? global : (window as typeof global);
|
|
6
|
+
|
|
7
|
+
if (__DEV__ && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
5
8
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
6
9
|
}
|
|
7
10
|
|
|
8
|
-
if (!
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
12
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
13
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map<
|
|
11
14
|
string,
|
|
12
15
|
ComputedConfigForKey
|
|
13
16
|
>();
|
|
14
|
-
|
|
17
|
+
globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
18
|
+
handlers: [],
|
|
19
|
+
processors: [],
|
|
20
|
+
};
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
function clearCache(): void {
|
|
18
|
-
|
|
24
|
+
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
19
25
|
}
|
|
20
26
|
|
|
21
27
|
function handleConfig(config: Config): Config {
|
|
@@ -56,18 +62,18 @@ function handleConfig(config: Config): Config {
|
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
export function configure(config: Config[]): void {
|
|
59
|
-
if (
|
|
65
|
+
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
60
66
|
// eslint-disable-next-line no-console
|
|
61
67
|
console.log('nightingale: warning: config overridden');
|
|
62
68
|
}
|
|
63
69
|
|
|
64
70
|
clearCache();
|
|
65
|
-
|
|
71
|
+
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
export function addConfig(config: Config, unshift = false): void {
|
|
69
75
|
config = handleConfig(config);
|
|
70
|
-
|
|
76
|
+
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
71
77
|
clearCache();
|
|
72
78
|
}
|
|
73
79
|
|
|
@@ -77,10 +83,10 @@ const configIsForKey = (key: string) => (config: Config) => {
|
|
|
77
83
|
return true;
|
|
78
84
|
};
|
|
79
85
|
|
|
80
|
-
|
|
86
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (
|
|
81
87
|
key: string,
|
|
82
88
|
): ComputedConfigForKey => {
|
|
83
|
-
const globalCache =
|
|
89
|
+
const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
84
90
|
|
|
85
91
|
const existingCache = globalCache.get(key);
|
|
86
92
|
|
|
@@ -93,7 +99,7 @@ global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (
|
|
|
93
99
|
processors: [],
|
|
94
100
|
};
|
|
95
101
|
|
|
96
|
-
|
|
102
|
+
globalOrWindow.__NIGHTINGALE_CONFIG
|
|
97
103
|
.filter(configIsForKey(key))
|
|
98
104
|
.some((config: Config) => {
|
|
99
105
|
if (config.handlers) loggerConfig.handlers.push(...config.handlers);
|
|
@@ -105,13 +111,13 @@ global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (
|
|
|
105
111
|
return loggerConfig;
|
|
106
112
|
};
|
|
107
113
|
|
|
108
|
-
if (
|
|
109
|
-
|
|
114
|
+
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
115
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (
|
|
110
116
|
key: string,
|
|
111
117
|
level: number,
|
|
112
118
|
): ComputedConfigForKey => {
|
|
113
119
|
const { handlers, processors }: ComputedConfigForKey =
|
|
114
|
-
|
|
120
|
+
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
|
|
115
121
|
|
|
116
122
|
return {
|
|
117
123
|
handlers: handlers.filter(
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-node14.cjs.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__ && global.__NIGHTINGALE_GLOBAL_HANDLERS) {\n throw new Error('nightingale: update all to ^5.0.0');\n}\n\nif (!global.__NIGHTINGALE_CONFIG) {\n global.__NIGHTINGALE_CONFIG = [];\n global.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map<\n string,\n ComputedConfigForKey\n >();\n global.__NIGHTINGALE_CONFIG_DEFAULT = { handlers: [], processors: [] };\n}\n\nfunction clearCache(): void {\n global.__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 (global.__NIGHTINGALE_CONFIG.length > 0) {\n // eslint-disable-next-line no-console\n console.log('nightingale: warning: config overridden');\n }\n\n clearCache();\n global.__NIGHTINGALE_CONFIG = config.map(handleConfig);\n}\n\nexport function addConfig(config: Config, unshift = false): void {\n config = handleConfig(config);\n global.__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\nglobal.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (\n key: string,\n): ComputedConfigForKey => {\n const globalCache = global.__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 global.__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 (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {\n global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (\n key: string,\n level: number,\n ): ComputedConfigForKey => {\n const { handlers, processors }: ComputedConfigForKey =\n global.__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":["__DEV__","global","__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,IAAIA,2CAAWC,MAAM,CAACC,6BAAtB,EAAqD;AACnD,QAAM,IAAIC,KAAJ,CAAU,mCAAV,CAAN;AACD;;AAED,IAAI,CAACF,MAAM,CAACG,oBAAZ,EAAkC;AAChCH,EAAAA,MAAM,CAACG,oBAAP,GAA8B,EAA9B;AACAH,EAAAA,MAAM,CAACI,8BAAP,GAAwC,IAAIC,GAAJ,EAAxC;AAIAL,EAAAA,MAAM,CAACM,4BAAP,GAAsC;AAAEC,IAAAA,QAAQ,EAAE,EAAZ;AAAgBC,IAAAA,UAAU,EAAE;AAA5B,GAAtC;AACD;;AAED,SAASC,UAAT,GAA4B;AAC1BT,EAAAA,MAAM,CAACI,8BAAP,CAAsCM,KAAtC;AACD;;AAED,SAASC,YAAT,CAAsBC,MAAtB,EAA8C;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