nightingale 11.7.0 → 11.8.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/.eslintrc.json +1 -1
- package/CHANGELOG.md +38 -0
- package/babel.config.cjs +14 -0
- package/dist/index-browser-dev.cjs.js +47 -29
- package/dist/index-browser-dev.cjs.js.map +1 -1
- package/dist/index-browser-dev.es.js +45 -27
- package/dist/index-browser-dev.es.js.map +1 -1
- package/dist/index-browser.cjs.js +47 -29
- package/dist/index-browser.cjs.js.map +1 -1
- package/dist/index-browser.es.js +45 -27
- package/dist/index-browser.es.js.map +1 -1
- package/dist/index-browsermodern-dev.es.js +13 -9
- package/dist/index-browsermodern-dev.es.js.map +1 -1
- package/dist/index-browsermodern.es.js +13 -9
- package/dist/index-browsermodern.es.js.map +1 -1
- package/dist/index-node12-dev.cjs.js +15 -11
- package/dist/index-node12-dev.cjs.js.map +1 -1
- package/dist/index-node12-dev.mjs +13 -9
- package/dist/index-node12-dev.mjs.map +1 -1
- package/dist/index-node12.cjs.js +15 -11
- package/dist/index-node12.cjs.js.map +1 -1
- package/dist/index-node12.mjs +13 -9
- package/dist/index-node12.mjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/package.json +25 -38
- package/rollup.config.mjs +3 -0
- package/src/config.ts +2 -4
- package/src/index.test.ts +1 -1
- package/src/index.ts +12 -10
- package/index.js +0 -6
package/dist/index-browser.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { Level, Level as levels } from 'nightingale-levels';
|
|
2
1
|
import { Logger } from 'nightingale-logger';
|
|
3
2
|
export { Logger, Logger as default } from 'nightingale-logger';
|
|
3
|
+
export { Level, Level as levels } from 'nightingale-levels';
|
|
4
4
|
|
|
5
5
|
if (!global.__NIGHTINGALE_CONFIG) {
|
|
6
6
|
global.__NIGHTINGALE_CONFIG = [];
|
|
@@ -63,7 +63,11 @@ function configure(config) {
|
|
|
63
63
|
clearCache();
|
|
64
64
|
global.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
65
65
|
}
|
|
66
|
-
function addConfig(config, unshift
|
|
66
|
+
function addConfig(config, unshift) {
|
|
67
|
+
if (unshift === void 0) {
|
|
68
|
+
unshift = false;
|
|
69
|
+
}
|
|
70
|
+
|
|
67
71
|
config = handleConfig(config);
|
|
68
72
|
|
|
69
73
|
global.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
@@ -71,28 +75,32 @@ function addConfig(config, unshift = false) {
|
|
|
71
75
|
clearCache();
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
var configIsForKey = function configIsForKey(key) {
|
|
79
|
+
return function (config) {
|
|
80
|
+
if (config.keys) return config.keys.includes(key);
|
|
81
|
+
if (config.pattern) return config.pattern.test(key);
|
|
82
|
+
return true;
|
|
83
|
+
};
|
|
78
84
|
};
|
|
79
85
|
|
|
80
|
-
global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key
|
|
81
|
-
|
|
82
|
-
|
|
86
|
+
global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = function (key) {
|
|
87
|
+
var globalCache = global.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
88
|
+
var existingCache = globalCache.get(key);
|
|
83
89
|
|
|
84
90
|
if (existingCache) {
|
|
85
91
|
return existingCache;
|
|
86
92
|
}
|
|
87
93
|
|
|
88
|
-
|
|
94
|
+
var loggerConfig = {
|
|
89
95
|
handlers: [],
|
|
90
96
|
processors: []
|
|
91
97
|
};
|
|
92
98
|
|
|
93
|
-
global.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config
|
|
94
|
-
|
|
95
|
-
|
|
99
|
+
global.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(function (config) {
|
|
100
|
+
var _loggerConfig$handler, _loggerConfig$process;
|
|
101
|
+
|
|
102
|
+
if (config.handlers) (_loggerConfig$handler = loggerConfig.handlers).push.apply(_loggerConfig$handler, config.handlers);
|
|
103
|
+
if (config.processors) (_loggerConfig$process = loggerConfig.processors).push.apply(_loggerConfig$process, config.processors);
|
|
96
104
|
return config.stop;
|
|
97
105
|
});
|
|
98
106
|
|
|
@@ -101,13 +109,15 @@ global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
|
101
109
|
};
|
|
102
110
|
|
|
103
111
|
if (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
104
|
-
global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
112
|
+
global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = function (key, level) {
|
|
113
|
+
var _global$__NIGHTINGALE = global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key),
|
|
114
|
+
handlers = _global$__NIGHTINGALE.handlers,
|
|
115
|
+
processors = _global$__NIGHTINGALE.processors;
|
|
108
116
|
|
|
109
117
|
return {
|
|
110
|
-
handlers: handlers.filter(
|
|
118
|
+
handlers: handlers.filter(function (handler) {
|
|
119
|
+
return level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key));
|
|
120
|
+
}),
|
|
111
121
|
processors
|
|
112
122
|
};
|
|
113
123
|
};
|
|
@@ -118,15 +128,23 @@ if (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
|
118
128
|
* @param {Logger} [logger]
|
|
119
129
|
*/
|
|
120
130
|
|
|
121
|
-
function listenUnhandledErrors(logger
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
process.on('
|
|
127
|
-
error,
|
|
128
|
-
|
|
129
|
-
|
|
131
|
+
function listenUnhandledErrors(logger) {
|
|
132
|
+
if (logger === void 0) {
|
|
133
|
+
logger = new Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
process.on('uncaughtException', function (error) {
|
|
137
|
+
logger.error('uncaughtException', {
|
|
138
|
+
error,
|
|
139
|
+
unhandled: true
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
process.on('unhandledRejection', function (error) {
|
|
143
|
+
logger.error('unhandledRejection', {
|
|
144
|
+
error,
|
|
145
|
+
unhandled: true
|
|
146
|
+
});
|
|
147
|
+
});
|
|
130
148
|
}
|
|
131
149
|
|
|
132
150
|
export { addConfig, configure, listenUnhandledErrors };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browser.es.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { POB_ENV } from 'pob-babel';\nimport type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nif (POB_ENV !== 'production' && 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 {
|
|
1
|
+
{"version":3,"file":"index-browser.es.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { POB_ENV } from 'pob-babel';\nimport type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nif (POB_ENV !== 'production' && 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 {\n /** @deprecated use named export instead */\n Logger as default,\n Logger,\n} 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":["global","__NIGHTINGALE_CONFIG","__NIGHTINGALE_LOGGER_MAP_CACHE","Map","__NIGHTINGALE_CONFIG_DEFAULT","handlers","processors","clearCache","clear","handleConfig","config","keys","pattern","Error","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":";;;;AAQA,IAAI,CAACA,MAAM,CAACC,oBAAZ,EAAkC;AAChCD,EAAAA,MAAM,CAACC,oBA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,CAIX;AAAA;;AACNC,EAAAA,OAAO,CAACC,EAAR,CAAW,mBAAX,EAAgC,UAACC,KAAD,EAAW;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,EAAiC,UAACC,KAAD,EAAW;AAC1CJ,IAAAA,MAAM,CAACI,KAAP,CAAa,oBAAb,EAAmC;AAAEA,MAAAA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAnC;AACD,GAFD;AAGD;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { Level, Level as levels } from 'nightingale-levels';
|
|
2
1
|
import { Logger } from 'nightingale-logger';
|
|
3
2
|
export { Logger, Logger as default } from 'nightingale-logger';
|
|
3
|
+
export { Level, Level as levels } from 'nightingale-levels';
|
|
4
4
|
|
|
5
5
|
if (global.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
6
6
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
@@ -124,14 +124,18 @@ if (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
|
124
124
|
*/
|
|
125
125
|
|
|
126
126
|
function listenUnhandledErrors(logger = new Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
|
|
127
|
-
process.on('uncaughtException', error =>
|
|
128
|
-
error,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
127
|
+
process.on('uncaughtException', error => {
|
|
128
|
+
logger.error('uncaughtException', {
|
|
129
|
+
error,
|
|
130
|
+
unhandled: true
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
process.on('unhandledRejection', error => {
|
|
134
|
+
logger.error('unhandledRejection', {
|
|
135
|
+
error,
|
|
136
|
+
unhandled: true
|
|
137
|
+
});
|
|
138
|
+
});
|
|
135
139
|
}
|
|
136
140
|
|
|
137
141
|
export { addConfig, configure, listenUnhandledErrors };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browsermodern-dev.es.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { POB_ENV } from 'pob-babel';\nimport type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nif (POB_ENV !== 'production' && 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 {
|
|
1
|
+
{"version":3,"file":"index-browsermodern-dev.es.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { POB_ENV } from 'pob-babel';\nimport type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nif (POB_ENV !== 'production' && 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 {\n /** @deprecated use named export instead */\n Logger as default,\n Logger,\n} 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":["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":";;;;AAIA,IAAgCA,MAAM,CAACC,6BAAvC,EAAsE;AACpE,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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A,SAAS,EAAE;AAApB,KAAnC;AACD,GAFD;AAGD;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { Level, Level as levels } from 'nightingale-levels';
|
|
2
1
|
import { Logger } from 'nightingale-logger';
|
|
3
2
|
export { Logger, Logger as default } from 'nightingale-logger';
|
|
3
|
+
export { Level, Level as levels } from 'nightingale-levels';
|
|
4
4
|
|
|
5
5
|
if (!global.__NIGHTINGALE_CONFIG) {
|
|
6
6
|
global.__NIGHTINGALE_CONFIG = [];
|
|
@@ -120,14 +120,18 @@ if (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
|
120
120
|
*/
|
|
121
121
|
|
|
122
122
|
function listenUnhandledErrors(logger = new Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
|
|
123
|
-
process.on('uncaughtException', error =>
|
|
124
|
-
error,
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
123
|
+
process.on('uncaughtException', error => {
|
|
124
|
+
logger.error('uncaughtException', {
|
|
125
|
+
error,
|
|
126
|
+
unhandled: true
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
process.on('unhandledRejection', error => {
|
|
130
|
+
logger.error('unhandledRejection', {
|
|
131
|
+
error,
|
|
132
|
+
unhandled: true
|
|
133
|
+
});
|
|
134
|
+
});
|
|
131
135
|
}
|
|
132
136
|
|
|
133
137
|
export { addConfig, configure, listenUnhandledErrors };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-browsermodern.es.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { POB_ENV } from 'pob-babel';\nimport type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nif (POB_ENV !== 'production' && 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 {
|
|
1
|
+
{"version":3,"file":"index-browsermodern.es.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { POB_ENV } from 'pob-babel';\nimport type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nif (POB_ENV !== 'production' && 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 {\n /** @deprecated use named export instead */\n Logger as default,\n Logger,\n} 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":["global","__NIGHTINGALE_CONFIG","__NIGHTINGALE_LOGGER_MAP_CACHE","Map","__NIGHTINGALE_CONFIG_DEFAULT","handlers","processors","clearCache","clear","handleConfig","config","keys","pattern","Error","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":";;;;AAQA,IAAI,CAACA,MAAM,CAACC,oBAAZ,EAAkC;AAChCD,EAAAA,MAAM,CAACC,oBAAP,GAA8B,EAA9B;AACAD,EAAAA,MAAM,CAACE,8BAAP,GAAwC,IAAIC,GAAJ,EAAxC;AAIAH,EAAAA,MAAM,CAACI,4BAAP,GAAsC;AAAEC,IAAAA,QAAQ,EAAE,EAAZ;AAAgBC,IAAAA,UAAU,EAAE;AAA5B,GAAtC;AACD;;AAED,SAASC,UAAT,GAA4B;AAC1BP,EAAAA,MAAM,CAACE,8BAAP,CAAsCM,KAAtC;AACD;;AAED,SAASC,YAAT,CAAsBC,MAAtB,EAA8C;AAC5C,MAAIA,MAAM,CAACC,IAAX,EAAiB;AACf,QAAID,MAAM,CAACE,OAAX,EAAoB;AAClB,YAAM,IAAIC,KAAJ,CAAU,iDAAV,CAAN;AACD;;AACD,QAAIH,MAAM,CAACI,GAAX,EAAgB;AACd,YAAM,IAAID,KAAJ,CAAU,8CAAV,CAAN;AACD;AACF,GAPD,MAOO,IAAIH,MAAM,CAACI,GAAX,EAAgB;AACrB,QAAIJ,MAAM,CAACE,OAAX,EAAoB;AAClB,YAAM,IAAIC,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GA,WAAO;AACLT,MAAAA,QAAQ,EAAEA,QAAQ,CAAC2B,MAAT,CACPjB,OAAD,IACEuB,KAAK,IAAIvB,OAAO,CAACwB,QAAjB,KACC,CAACxB,OAAO,CAACyB,UAAT,IAAuBzB,OAAO,CAACyB,UAAR,CAAmBF,KAAnB,EAA0BxB,GAA1B,CADxB,CAFM,CADL;AAMLR,MAAAA;AANK,KAAP;AAQD,GAfD;AAgBD;;ACnHD;AACA;AACA;AACA;;AACO,SAASmC,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;;;;"}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const nightingaleLevels = require('nightingale-levels');
|
|
6
5
|
const nightingaleLogger = require('nightingale-logger');
|
|
6
|
+
const nightingaleLevels = require('nightingale-levels');
|
|
7
7
|
|
|
8
8
|
if (global.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
9
9
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
@@ -127,20 +127,24 @@ if (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
|
127
127
|
*/
|
|
128
128
|
|
|
129
129
|
function listenUnhandledErrors(logger = new nightingaleLogger.Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
|
|
130
|
-
process.on('uncaughtException', error =>
|
|
131
|
-
error,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
130
|
+
process.on('uncaughtException', error => {
|
|
131
|
+
logger.error('uncaughtException', {
|
|
132
|
+
error,
|
|
133
|
+
unhandled: true
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
process.on('unhandledRejection', error => {
|
|
137
|
+
logger.error('unhandledRejection', {
|
|
138
|
+
error,
|
|
139
|
+
unhandled: true
|
|
140
|
+
});
|
|
141
|
+
});
|
|
138
142
|
}
|
|
139
143
|
|
|
144
|
+
exports.Logger = nightingaleLogger.Logger;
|
|
145
|
+
exports["default"] = nightingaleLogger.Logger;
|
|
140
146
|
exports.Level = nightingaleLevels.Level;
|
|
141
147
|
exports.levels = nightingaleLevels.Level;
|
|
142
|
-
exports.Logger = nightingaleLogger.Logger;
|
|
143
|
-
exports.default = nightingaleLogger.Logger;
|
|
144
148
|
exports.addConfig = addConfig;
|
|
145
149
|
exports.configure = configure;
|
|
146
150
|
exports.listenUnhandledErrors = listenUnhandledErrors;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-node12-dev.cjs.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { POB_ENV } from 'pob-babel';\nimport type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nif (POB_ENV !== 'production' && 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 {
|
|
1
|
+
{"version":3,"file":"index-node12-dev.cjs.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { POB_ENV } from 'pob-babel';\nimport type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nif (POB_ENV !== 'production' && 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 {\n /** @deprecated use named export instead */\n Logger as default,\n Logger,\n} 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":["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":";;;;;;;AAIA,IAAgCA,MAAM,CAACC,6BAAvC,EAAsE;AACpE,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;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,I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T,CACPjB,OAAD,IACEuB,KAAK,IAAIvB,OAAO,CAACwB,QAAjB,KACC,CAACxB,OAAO,CAACyB,UAAT,IAAuBzB,OAAO,CAACyB,UAAR,CAAmBF,KAAnB,EAA0BxB,GAA1B,CADxB,CAFM,CADL;AAMLP,MAAAA;AANK,KAAP;AAQD,GAfD;AAgBD;;ACnHD;AACA;AACA;AACA;;AACO,SAASkC,qBAAT,CACLC,MAAc,GAAG,IAAIC,wBAAJ,CACf,mCADe,EAEf,iBAFe,CADZ,EAKC;AACNC,EAAAA,OAAO,CAACC,EAAR,CAAW,mBAAX,EAAiCC,KAAD,IAAW;AACzCJ,IAAAA,MAAM,CAACI,KAAP,CAAa,mBAAb,EAAkC;AAAEA,MAAAA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAlC;AACD,GAFD;AAGAH,EAAAA,OAAO,CAACC,EAAR,CAAW,oBAAX,EAAkCC,KAAD,IAAW;AAC1CJ,IAAAA,MAAM,CAACI,KAAP,CAAa,oBAAb,EAAmC;AAAEA,MAAAA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAnC;AACD,GAFD;AAGD;;;;;;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { Level, Level as levels } from 'nightingale-levels';
|
|
2
1
|
import { Logger } from 'nightingale-logger';
|
|
3
2
|
export { Logger, Logger as default } from 'nightingale-logger';
|
|
3
|
+
export { Level, Level as levels } from 'nightingale-levels';
|
|
4
4
|
|
|
5
5
|
if (global.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
6
6
|
throw new Error('nightingale: update all to ^5.0.0');
|
|
@@ -124,14 +124,18 @@ if (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
|
124
124
|
*/
|
|
125
125
|
|
|
126
126
|
function listenUnhandledErrors(logger = new Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
|
|
127
|
-
process.on('uncaughtException', error =>
|
|
128
|
-
error,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
127
|
+
process.on('uncaughtException', error => {
|
|
128
|
+
logger.error('uncaughtException', {
|
|
129
|
+
error,
|
|
130
|
+
unhandled: true
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
process.on('unhandledRejection', error => {
|
|
134
|
+
logger.error('unhandledRejection', {
|
|
135
|
+
error,
|
|
136
|
+
unhandled: true
|
|
137
|
+
});
|
|
138
|
+
});
|
|
135
139
|
}
|
|
136
140
|
|
|
137
141
|
export { addConfig, configure, listenUnhandledErrors };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-node12-dev.mjs","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { POB_ENV } from 'pob-babel';\nimport type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nif (POB_ENV !== 'production' && 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 {
|
|
1
|
+
{"version":3,"file":"index-node12-dev.mjs","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { POB_ENV } from 'pob-babel';\nimport type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nif (POB_ENV !== 'production' && 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 {\n /** @deprecated use named export instead */\n Logger as default,\n Logger,\n} 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":["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":";;;;AAIA,I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AX,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-node12.cjs.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
const nightingaleLevels = require('nightingale-levels');
|
|
6
5
|
const nightingaleLogger = require('nightingale-logger');
|
|
6
|
+
const nightingaleLevels = require('nightingale-levels');
|
|
7
7
|
|
|
8
8
|
if (!global.__NIGHTINGALE_CONFIG) {
|
|
9
9
|
global.__NIGHTINGALE_CONFIG = [];
|
|
@@ -123,20 +123,24 @@ if (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
|
123
123
|
*/
|
|
124
124
|
|
|
125
125
|
function listenUnhandledErrors(logger = new nightingaleLogger.Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
|
|
126
|
-
process.on('uncaughtException', error =>
|
|
127
|
-
error,
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
126
|
+
process.on('uncaughtException', error => {
|
|
127
|
+
logger.error('uncaughtException', {
|
|
128
|
+
error,
|
|
129
|
+
unhandled: true
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
process.on('unhandledRejection', error => {
|
|
133
|
+
logger.error('unhandledRejection', {
|
|
134
|
+
error,
|
|
135
|
+
unhandled: true
|
|
136
|
+
});
|
|
137
|
+
});
|
|
134
138
|
}
|
|
135
139
|
|
|
140
|
+
exports.Logger = nightingaleLogger.Logger;
|
|
141
|
+
exports["default"] = nightingaleLogger.Logger;
|
|
136
142
|
exports.Level = nightingaleLevels.Level;
|
|
137
143
|
exports.levels = nightingaleLevels.Level;
|
|
138
|
-
exports.Logger = nightingaleLogger.Logger;
|
|
139
|
-
exports.default = nightingaleLogger.Logger;
|
|
140
144
|
exports.addConfig = addConfig;
|
|
141
145
|
exports.configure = configure;
|
|
142
146
|
exports.listenUnhandledErrors = listenUnhandledErrors;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-node12.cjs.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { POB_ENV } from 'pob-babel';\nimport type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nif (POB_ENV !== 'production' && 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 {
|
|
1
|
+
{"version":3,"file":"index-node12.cjs.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import { POB_ENV } from 'pob-babel';\nimport type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\nif (POB_ENV !== 'production' && 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 {\n /** @deprecated use named export instead */\n Logger as default,\n Logger,\n} 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":["global","__NIGHTINGALE_CONFIG","__NIGHTINGALE_LOGGER_MAP_CACHE","Map","__NIGHTINGALE_CONFIG_DEFAULT","handlers","processors","clearCache","clear","handleConfig","config","keys","pattern","Error","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":";;;;;;;AAQA,IAAI,CAACA,MAAM,CAACC,oBAAZ,EAAkC;AAChCD,EAAAA,MAAM,CAACC,oBAAP,GAA8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