nightingale 12.1.3 → 13.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/README.md +4 -0
- package/dist/{config.d.ts → definitions/config.d.ts} +0 -0
- package/dist/definitions/config.d.ts.map +1 -0
- package/dist/{index.d.ts → definitions/index.d.ts} +0 -0
- package/dist/definitions/index.d.ts.map +1 -0
- package/dist/definitions/index.test.d.ts +2 -0
- package/dist/definitions/index.test.d.ts.map +1 -0
- package/dist/index-browser.es.js +18 -43
- package/dist/index-browser.es.js.map +1 -1
- package/dist/index-browsermodern.es.js +16 -38
- package/dist/index-browsermodern.es.js.map +1 -1
- package/dist/{index-node14.mjs → index-node16.mjs} +17 -39
- package/dist/index-node16.mjs.map +1 -0
- package/package.json +27 -44
- package/src/config.ts +21 -15
- package/dist/config.d.ts.map +0 -1
- package/dist/index-browser.cjs.js +0 -163
- package/dist/index-browser.cjs.js.map +0 -1
- package/dist/index-node14.cjs.js +0 -150
- package/dist/index-node14.cjs.js.map +0 -1
- package/dist/index-node14.mjs.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/rollup.config.mjs +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-node16.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","__NIGHTINGALE_GLOBAL_HANDLERS","Error","__NIGHTINGALE_CONFIG","__NIGHTINGALE_LOGGER_MAP_CACHE","Map","__NIGHTINGALE_CONFIG_DEFAULT","handlers","processors","clearCache","clear","handleConfig","config","keys","pattern","key","handler","processor","configure","length","console","log","map","addConfig","unshift","configIsForKey","includes","test","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER","globalCache","existingCache","get","loggerConfig","filter","some","push","stop","set","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD","level","minLevel","isHandling","listenUnhandledErrors","logger","Logger","process","on","error","unhandled"],"mappings":";;;;AAGA,MAAMA,cAA6B,GACjC,OAAOC,MAAM,KAAK,WAAW,GAAGA,MAAM,GAAIC,MAAwB,CAAA;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V,cAAc,CAAC8B,mCAAmC,CAACb,GAAG,CAAC,CAAA;IAEzD,OAAO;MACLR,QAAQ,EAAEA,QAAQ,CAAC0B,MAAM,CACtBjB,OAAgB,IACfuB,KAAK,IAAIvB,OAAO,CAACwB,QAAQ,KACxB,CAACxB,OAAO,CAACyB,UAAU,IAAIzB,OAAO,CAACyB,UAAU,CAACF,KAAK,EAAExB,GAAG,CAAC,CAAC,CAC1D;AACDP,MAAAA,UAAAA;KACD,CAAA;GACF,CAAA;AACH;;AC5HA;AACA;AACA;AACA;AACO,SAASkC,qBAAqB,CACnCC,MAAc,GAAG,IAAIC,MAAM,CACzB,mCAAmC,EACnC,iBAAiB,CAClB,EACK;AACNC,EAAAA,OAAO,CAACC,EAAE,CAAC,mBAAmB,EAAGC,KAAK,IAAK;AACzCJ,IAAAA,MAAM,CAACI,KAAK,CAAC,mBAAmB,EAAE;MAAEA,KAAK;AAAEC,MAAAA,SAAS,EAAE,IAAA;AAAK,KAAC,CAAC,CAAA;AAC/D,GAAC,CAAC,CAAA;AACFH,EAAAA,OAAO,CAACC,EAAE,CAAC,oBAAoB,EAAGC,KAAK,IAAK;AAC1CJ,IAAAA,MAAM,CAACI,KAAK,CAAC,oBAAoB,EAAE;MAAEA,KAAK;AAAEC,MAAAA,SAAS,EAAE,IAAA;AAAK,KAAC,CAAC,CAAA;AAChE,GAAC,CAAC,CAAA;AACJ;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nightingale",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.0",
|
|
4
4
|
"description": "Logger for browser and node",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"logger"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"homepage": "https://github.com/christophehurpeau/nightingale",
|
|
16
16
|
"type": "module",
|
|
17
17
|
"engines": {
|
|
18
|
-
"node": "
|
|
18
|
+
"node": ">=16.0.0"
|
|
19
19
|
},
|
|
20
20
|
"browserslist": [
|
|
21
21
|
"defaults",
|
|
@@ -24,65 +24,48 @@
|
|
|
24
24
|
"not safari < 10",
|
|
25
25
|
"not ios_saf < 10"
|
|
26
26
|
],
|
|
27
|
-
"main": "./dist/index-
|
|
28
|
-
"types": "./dist/index.d.ts",
|
|
27
|
+
"main": "./dist/index-node16.mjs",
|
|
28
|
+
"types": "./dist/definitions/index.d.ts",
|
|
29
29
|
"module": "./dist/index-browser.es.js",
|
|
30
30
|
"browser": "./dist/index-browser.es.js",
|
|
31
31
|
"exports": {
|
|
32
32
|
"./package.json": "./package.json",
|
|
33
33
|
".": {
|
|
34
34
|
"node": {
|
|
35
|
-
"import": "./dist/index-
|
|
36
|
-
"require": "./dist/index-node14.cjs.js"
|
|
35
|
+
"import": "./dist/index-node16.mjs"
|
|
37
36
|
},
|
|
38
37
|
"browser": {
|
|
39
38
|
"browser:modern": {
|
|
40
39
|
"import": "./dist/index-browsermodern.es.js"
|
|
41
40
|
},
|
|
42
|
-
"import": "./dist/index-browser.es.js"
|
|
43
|
-
"require": "./dist/index-browser.cjs.js"
|
|
41
|
+
"import": "./dist/index-browser.es.js"
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
},
|
|
47
|
-
"module:node": "./dist/index-node14.mjs",
|
|
48
|
-
"module:modern-browsers": "./dist/index-browsermodern.es.js",
|
|
49
45
|
"sideEffects": false,
|
|
50
46
|
"scripts": {
|
|
51
|
-
"build": "
|
|
52
|
-
"build:definitions": "tsc -p
|
|
53
|
-
"clean": "
|
|
47
|
+
"build": "yarn clean:build && rollup --config rollup.config.mjs && yarn run build:definitions",
|
|
48
|
+
"build:definitions": "tsc -p",
|
|
49
|
+
"clean": "yarn clean:build",
|
|
50
|
+
"clean:build": "pob-babel-clean-out dist",
|
|
54
51
|
"lint": "yarn run lint:eslint",
|
|
55
|
-
"lint:eslint": "
|
|
56
|
-
"
|
|
57
|
-
|
|
58
|
-
"prettier": {
|
|
59
|
-
"trailingComma": "all",
|
|
60
|
-
"singleQuote": true,
|
|
61
|
-
"arrowParens": "always"
|
|
52
|
+
"lint:eslint": "yarn ../.. run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet packages/nightingale",
|
|
53
|
+
"test": "yarn ../../ run test -- packages/nightingale",
|
|
54
|
+
"watch": "yarn clean:build && rollup --config rollup.config.mjs --watch"
|
|
62
55
|
},
|
|
56
|
+
"prettier": "@pob/root/prettier-config",
|
|
63
57
|
"pob": {
|
|
64
58
|
"babelEnvs": [
|
|
65
59
|
{
|
|
66
60
|
"target": "node",
|
|
67
|
-
"version": "
|
|
68
|
-
"formats": [
|
|
69
|
-
"cjs",
|
|
70
|
-
"es"
|
|
71
|
-
]
|
|
61
|
+
"version": "16"
|
|
72
62
|
},
|
|
73
63
|
{
|
|
74
64
|
"target": "browser",
|
|
75
|
-
"version": "modern"
|
|
76
|
-
"formats": [
|
|
77
|
-
"es"
|
|
78
|
-
]
|
|
65
|
+
"version": "modern"
|
|
79
66
|
},
|
|
80
67
|
{
|
|
81
|
-
"target": "browser"
|
|
82
|
-
"formats": [
|
|
83
|
-
"cjs",
|
|
84
|
-
"es"
|
|
85
|
-
]
|
|
68
|
+
"target": "browser"
|
|
86
69
|
}
|
|
87
70
|
],
|
|
88
71
|
"entries": [
|
|
@@ -90,18 +73,18 @@
|
|
|
90
73
|
]
|
|
91
74
|
},
|
|
92
75
|
"dependencies": {
|
|
93
|
-
"@types/node": ">=
|
|
94
|
-
"nightingale-levels": "
|
|
95
|
-
"nightingale-logger": "
|
|
96
|
-
"nightingale-types": "
|
|
76
|
+
"@types/node": ">=16.0.0",
|
|
77
|
+
"nightingale-levels": "13.0.0",
|
|
78
|
+
"nightingale-logger": "13.0.0",
|
|
79
|
+
"nightingale-types": "13.0.0"
|
|
97
80
|
},
|
|
98
81
|
"devDependencies": {
|
|
99
|
-
"@babel/core": "7.
|
|
100
|
-
"@babel/preset-env": "7.
|
|
82
|
+
"@babel/core": "7.20.2",
|
|
83
|
+
"@babel/preset-env": "7.20.2",
|
|
101
84
|
"babel-preset-modern-browsers": "15.0.2",
|
|
102
|
-
"nightingale-string": "
|
|
103
|
-
"pob-babel": "
|
|
104
|
-
"typescript": "4.
|
|
85
|
+
"nightingale-string": "13.0.0",
|
|
86
|
+
"pob-babel": "35.3.0",
|
|
87
|
+
"typescript": "4.9.3"
|
|
105
88
|
},
|
|
106
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "52cf7e3c8762a07891da9dde497ec03298c15654"
|
|
107
90
|
}
|
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(
|
package/dist/config.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwB,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAyDvE,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAQhD;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,IAAI,CAI/D"}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var nightingaleLogger = require('nightingale-logger');
|
|
6
|
-
var nightingaleLevels = require('nightingale-levels');
|
|
7
|
-
|
|
8
|
-
if ((process.env.NODE_ENV !== "production") && global.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
9
|
-
throw new Error('nightingale: update all to ^5.0.0');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (!global.__NIGHTINGALE_CONFIG) {
|
|
13
|
-
global.__NIGHTINGALE_CONFIG = [];
|
|
14
|
-
global.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
15
|
-
global.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
16
|
-
handlers: [],
|
|
17
|
-
processors: []
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function clearCache() {
|
|
22
|
-
global.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function handleConfig(config) {
|
|
26
|
-
if (config.keys) {
|
|
27
|
-
if (config.pattern) {
|
|
28
|
-
throw new Error('Cannot have key and pattern for the same config');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (config.key) {
|
|
32
|
-
throw new Error('Cannot have key and keys for the same config');
|
|
33
|
-
}
|
|
34
|
-
} else if (config.key) {
|
|
35
|
-
if (config.pattern) {
|
|
36
|
-
throw new Error('Cannot have key and pattern for the same config');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
config.keys = [config.key];
|
|
40
|
-
delete config.key;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (config.handler) {
|
|
44
|
-
if (config.handlers) {
|
|
45
|
-
throw new Error('Cannot have handler and handlers for the same config');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
config.handlers = [config.handler];
|
|
49
|
-
delete config.handler;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (config.processor) {
|
|
53
|
-
if (config.processors) {
|
|
54
|
-
throw new Error('Cannot have processors and processors for the same config');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
config.processors = [config.processor];
|
|
58
|
-
delete config.processor;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return config;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function configure(config) {
|
|
65
|
-
if (global.__NIGHTINGALE_CONFIG.length > 0) {
|
|
66
|
-
// eslint-disable-next-line no-console
|
|
67
|
-
console.log('nightingale: warning: config overridden');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
clearCache();
|
|
71
|
-
global.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
72
|
-
}
|
|
73
|
-
function addConfig(config, unshift) {
|
|
74
|
-
if (unshift === void 0) {
|
|
75
|
-
unshift = false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
config = handleConfig(config);
|
|
79
|
-
|
|
80
|
-
global.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
81
|
-
|
|
82
|
-
clearCache();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
var configIsForKey = function configIsForKey(key) {
|
|
86
|
-
return function (config) {
|
|
87
|
-
if (config.keys) return config.keys.includes(key);
|
|
88
|
-
if (config.pattern) return config.pattern.test(key);
|
|
89
|
-
return true;
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = function (key) {
|
|
94
|
-
var globalCache = global.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
95
|
-
var existingCache = globalCache.get(key);
|
|
96
|
-
|
|
97
|
-
if (existingCache) {
|
|
98
|
-
return existingCache;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
var loggerConfig = {
|
|
102
|
-
handlers: [],
|
|
103
|
-
processors: []
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
global.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(function (config) {
|
|
107
|
-
var _loggerConfig$handler, _loggerConfig$process;
|
|
108
|
-
|
|
109
|
-
if (config.handlers) (_loggerConfig$handler = loggerConfig.handlers).push.apply(_loggerConfig$handler, config.handlers);
|
|
110
|
-
if (config.processors) (_loggerConfig$process = loggerConfig.processors).push.apply(_loggerConfig$process, config.processors);
|
|
111
|
-
return config.stop;
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
globalCache.set(key, loggerConfig);
|
|
115
|
-
return loggerConfig;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
if (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
119
|
-
global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = function (key, level) {
|
|
120
|
-
var _global$__NIGHTINGALE = global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key),
|
|
121
|
-
handlers = _global$__NIGHTINGALE.handlers,
|
|
122
|
-
processors = _global$__NIGHTINGALE.processors;
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
handlers: handlers.filter(function (handler) {
|
|
126
|
-
return level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key));
|
|
127
|
-
}),
|
|
128
|
-
processors: processors
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* listen to uncaughtException and unhandledRejection
|
|
135
|
-
* @param {Logger} [logger]
|
|
136
|
-
*/
|
|
137
|
-
|
|
138
|
-
function listenUnhandledErrors(logger) {
|
|
139
|
-
if (logger === void 0) {
|
|
140
|
-
logger = new nightingaleLogger.Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
process.on('uncaughtException', function (error) {
|
|
144
|
-
logger.error('uncaughtException', {
|
|
145
|
-
error: error,
|
|
146
|
-
unhandled: true
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
process.on('unhandledRejection', function (error) {
|
|
150
|
-
logger.error('unhandledRejection', {
|
|
151
|
-
error: error,
|
|
152
|
-
unhandled: true
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
exports.Logger = nightingaleLogger.Logger;
|
|
158
|
-
exports.Level = nightingaleLevels.Level;
|
|
159
|
-
exports.levels = nightingaleLevels.Level;
|
|
160
|
-
exports.addConfig = addConfig;
|
|
161
|
-
exports.configure = configure;
|
|
162
|
-
exports.listenUnhandledErrors = listenUnhandledErrors;
|
|
163
|
-
//# sourceMappingURL=index-browser.cjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-browser.cjs.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\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;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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;AAGA,WAAO;AACLD,MAAAA,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;;ACtHD;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-node14.cjs.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const nightingaleLogger = require('nightingale-logger');
|
|
6
|
-
const nightingaleLevels = require('nightingale-levels');
|
|
7
|
-
|
|
8
|
-
if ((process.env.NODE_ENV !== "production") && global.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
9
|
-
throw new Error('nightingale: update all to ^5.0.0');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (!global.__NIGHTINGALE_CONFIG) {
|
|
13
|
-
global.__NIGHTINGALE_CONFIG = [];
|
|
14
|
-
global.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
15
|
-
global.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
16
|
-
handlers: [],
|
|
17
|
-
processors: []
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function clearCache() {
|
|
22
|
-
global.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function handleConfig(config) {
|
|
26
|
-
if (config.keys) {
|
|
27
|
-
if (config.pattern) {
|
|
28
|
-
throw new Error('Cannot have key and pattern for the same config');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (config.key) {
|
|
32
|
-
throw new Error('Cannot have key and keys for the same config');
|
|
33
|
-
}
|
|
34
|
-
} else if (config.key) {
|
|
35
|
-
if (config.pattern) {
|
|
36
|
-
throw new Error('Cannot have key and pattern for the same config');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
config.keys = [config.key];
|
|
40
|
-
delete config.key;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (config.handler) {
|
|
44
|
-
if (config.handlers) {
|
|
45
|
-
throw new Error('Cannot have handler and handlers for the same config');
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
config.handlers = [config.handler];
|
|
49
|
-
delete config.handler;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (config.processor) {
|
|
53
|
-
if (config.processors) {
|
|
54
|
-
throw new Error('Cannot have processors and processors for the same config');
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
config.processors = [config.processor];
|
|
58
|
-
delete config.processor;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return config;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function configure(config) {
|
|
65
|
-
if (global.__NIGHTINGALE_CONFIG.length > 0) {
|
|
66
|
-
// eslint-disable-next-line no-console
|
|
67
|
-
console.log('nightingale: warning: config overridden');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
clearCache();
|
|
71
|
-
global.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
72
|
-
}
|
|
73
|
-
function addConfig(config, unshift = false) {
|
|
74
|
-
config = handleConfig(config);
|
|
75
|
-
|
|
76
|
-
global.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
77
|
-
|
|
78
|
-
clearCache();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const configIsForKey = key => config => {
|
|
82
|
-
if (config.keys) return config.keys.includes(key);
|
|
83
|
-
if (config.pattern) return config.pattern.test(key);
|
|
84
|
-
return true;
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
88
|
-
const globalCache = global.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
89
|
-
const existingCache = globalCache.get(key);
|
|
90
|
-
|
|
91
|
-
if (existingCache) {
|
|
92
|
-
return existingCache;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const loggerConfig = {
|
|
96
|
-
handlers: [],
|
|
97
|
-
processors: []
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
global.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
|
|
101
|
-
if (config.handlers) loggerConfig.handlers.push(...config.handlers);
|
|
102
|
-
if (config.processors) loggerConfig.processors.push(...config.processors);
|
|
103
|
-
return config.stop;
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
globalCache.set(key, loggerConfig);
|
|
107
|
-
return loggerConfig;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
if (global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
111
|
-
global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
|
|
112
|
-
const {
|
|
113
|
-
handlers,
|
|
114
|
-
processors
|
|
115
|
-
} = global.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
|
|
116
|
-
|
|
117
|
-
return {
|
|
118
|
-
handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
|
|
119
|
-
processors
|
|
120
|
-
};
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* listen to uncaughtException and unhandledRejection
|
|
126
|
-
* @param {Logger} [logger]
|
|
127
|
-
*/
|
|
128
|
-
|
|
129
|
-
function listenUnhandledErrors(logger = new nightingaleLogger.Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
|
|
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
|
-
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
exports.Logger = nightingaleLogger.Logger;
|
|
145
|
-
exports.Level = nightingaleLevels.Level;
|
|
146
|
-
exports.levels = nightingaleLevels.Level;
|
|
147
|
-
exports.addConfig = addConfig;
|
|
148
|
-
exports.configure = configure;
|
|
149
|
-
exports.listenUnhandledErrors = listenUnhandledErrors;
|
|
150
|
-
//# sourceMappingURL=index-node14.cjs.js.map
|
|
@@ -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":";;;;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ACC,EAAR,CAAW,mBAAX,EAAiCC,KAAD,IAAW;AACzCJ,IAAAA,MAAM,CAACI,KAAP,CAAa,mBAAb,EAAkC;AAAEA,MAAAA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAlC;AACD,GAFD;AAGAH,EAAAA,OAAO,CAACC,EAAR,CAAW,oBAAX,EAAkCC,KAAD,IAAW;AAC1CJ,IAAAA,MAAM,CAACI,KAAP,CAAa,oBAAb,EAAmC;AAAEA,MAAAA,KAAF;AAASC,MAAAA,SAAS,EAAE;AAApB,KAAnC;AACD,GAFD;AAGD;;;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-node14.mjs","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler } from 'nightingale-types';\n\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;AAC5C,MAAIA,MAAM,CAACC,IAAX,EAAiB;AACf,QAAID,MAAM,CAACE,OAAX,EAAoB;AAClB,YAAM,IAAIZ,KAAJ,CAAU,iDAAV,CAAN;AAC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,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEhD;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,GAAE,MAGP,GACA,IAAI,CAON"}
|
package/rollup.config.mjs
DELETED