axe 9.0.0 → 10.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/README.md +723 -179
- package/dist/axe.js +1151 -6809
- package/dist/axe.min.js +1 -1
- package/lib/index.js +253 -115
- package/package.json +20 -15
package/lib/index.js
CHANGED
|
@@ -3,23 +3,29 @@
|
|
|
3
3
|
// eslint-disable-next-line import/no-unassigned-import
|
|
4
4
|
require('console-polyfill');
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const combine = require('maybe-combine-errors');
|
|
7
7
|
|
|
8
8
|
const format = require('@ladjs/format-util');
|
|
9
9
|
|
|
10
10
|
const formatSpecifiers = require('format-specifiers');
|
|
11
11
|
|
|
12
|
+
const get = require('@strikeentco/get');
|
|
13
|
+
|
|
12
14
|
const isError = require('iserror');
|
|
13
15
|
|
|
14
|
-
const
|
|
16
|
+
const mergeOptions = require('merge-options');
|
|
17
|
+
|
|
18
|
+
const pMapSeries = require('p-map-series');
|
|
15
19
|
|
|
16
20
|
const parseAppInfo = require('parse-app-info');
|
|
17
21
|
|
|
18
22
|
const parseErr = require('parse-err');
|
|
19
23
|
|
|
20
|
-
const
|
|
24
|
+
const pickDeep = require('pick-deep');
|
|
25
|
+
|
|
26
|
+
const set = require('@strikeentco/set');
|
|
21
27
|
|
|
22
|
-
const
|
|
28
|
+
const unset = require('unset-value');
|
|
23
29
|
|
|
24
30
|
const {
|
|
25
31
|
boolean
|
|
@@ -33,8 +39,39 @@ const aliases = {
|
|
|
33
39
|
warning: 'warn',
|
|
34
40
|
err: 'error'
|
|
35
41
|
};
|
|
36
|
-
const
|
|
37
|
-
|
|
42
|
+
const levelError = `\`level\` invalid, must be: ${levels.join(', ')}`; // <https://github.com/sindresorhus/is-plain-obj/blob/main/index.js>
|
|
43
|
+
|
|
44
|
+
function isPlainObject(value) {
|
|
45
|
+
if (typeof value !== 'object' || value === null) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const prototype = Object.getPrototypeOf(value);
|
|
50
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
|
|
51
|
+
} // <https://github.com/GeenenTijd/dotify/blob/master/dotify.js>
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
function dotifyToArray(obj) {
|
|
55
|
+
const res = [];
|
|
56
|
+
|
|
57
|
+
function recurse(obj, current) {
|
|
58
|
+
for (const key of Object.keys(obj)) {
|
|
59
|
+
const value = obj[key];
|
|
60
|
+
const newKey = current ? current + '.' + key : key; // joined key with dot
|
|
61
|
+
// if (value && typeof value === 'object' && !(value instanceof Date) && !ObjectID.isValid(value)) {
|
|
62
|
+
|
|
63
|
+
if (isPlainObject(value)) {
|
|
64
|
+
recurse(value, newKey); // it's a nested object, so do it again
|
|
65
|
+
} else {
|
|
66
|
+
res.push(newKey);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
recurse(obj);
|
|
72
|
+
return res;
|
|
73
|
+
} // <https://stackoverflow.com/a/43233163>
|
|
74
|
+
|
|
38
75
|
|
|
39
76
|
function isEmpty(value) {
|
|
40
77
|
return value === undefined || value === null || typeof value === 'object' && Object.keys(value).length === 0 || typeof value === 'string' && value.trim().length === 0;
|
|
@@ -60,43 +97,42 @@ function isFunction(value) {
|
|
|
60
97
|
return typeof value === 'function';
|
|
61
98
|
}
|
|
62
99
|
|
|
63
|
-
function isBoolean(value) {
|
|
64
|
-
return typeof value === 'boolean';
|
|
65
|
-
}
|
|
66
|
-
|
|
67
100
|
class Axe {
|
|
68
101
|
constructor() {
|
|
69
102
|
var _this = this;
|
|
70
103
|
|
|
71
104
|
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
105
|
+
const remappedFields = {};
|
|
106
|
+
|
|
107
|
+
if (process.env.AXE_REMAPPED_META_FIELDS) {
|
|
108
|
+
const arr = process.env.AXE_REMAPPED_META_FIELDS.split(',').map(v => v.split(':'));
|
|
109
|
+
|
|
110
|
+
for (const [prop, value] of arr) {
|
|
111
|
+
remappedFields[prop] = value;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this.config = mergeOptions({
|
|
116
|
+
showStack: process.env.AXE_SHOW_STACK ? boolean(process.env.AXE_SHOW_STACK) : true,
|
|
117
|
+
meta: Object.assign({
|
|
118
|
+
show: process.env.AXE_SHOW_META ? boolean(process.env.AXE_SHOW_META) : true,
|
|
119
|
+
remappedFields,
|
|
120
|
+
omittedFields: process.env.AXE_OMIT_META_FIELDS ? process.env.AXE_OMIT_META_FIELDS.split(',').map(s => s.trim()) : ['level', 'err', 'app', 'args'],
|
|
121
|
+
pickedFields: process.env.AXE_PICK_META_FIELDS ? process.env.AXE_PICK_META_FIELDS.split(',').map(s => s.trim()) : [],
|
|
122
|
+
cleanupRemapping: true
|
|
123
|
+
}, typeof config.meta === 'object' ? config.meta : {}),
|
|
124
|
+
version: pkg.version,
|
|
84
125
|
silent: false,
|
|
85
126
|
logger: console,
|
|
86
127
|
name: false,
|
|
87
128
|
level: 'info',
|
|
88
129
|
levels: ['info', 'warn', 'error', 'fatal'],
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (this.config.showMeta) {
|
|
96
|
-
this.config.meta.show = this.config.showMeta;
|
|
97
|
-
delete this.config.showMeta;
|
|
98
|
-
}
|
|
99
|
-
|
|
130
|
+
appInfo: process.env.AXE_APP_INFO ? boolean(process.env.AXE_APP_INFO) : true,
|
|
131
|
+
hooks: Object.assign({
|
|
132
|
+
pre: [],
|
|
133
|
+
post: []
|
|
134
|
+
}, typeof config.hooks === 'object' ? config.hooks : {})
|
|
135
|
+
}, config);
|
|
100
136
|
this.appInfo = this.config.appInfo ? isFunction(parseAppInfo) ? parseAppInfo() : false : false;
|
|
101
137
|
this.log = this.log.bind(this); // Inherit methods from parent logger
|
|
102
138
|
|
|
@@ -108,6 +144,16 @@ class Axe {
|
|
|
108
144
|
|
|
109
145
|
|
|
110
146
|
for (const element of levels) {
|
|
147
|
+
// Ensure function exists in logger passed
|
|
148
|
+
if (typeof this.config.logger[element] !== 'function') {
|
|
149
|
+
if (element === 'fatal') {
|
|
150
|
+
this.config.logger.fatal = this.config.logger.error || this.config.logger.info || this.config.logger.log;
|
|
151
|
+
} else {
|
|
152
|
+
this.config.logger[element] = this.config.logger.info || this.config.logger.log;
|
|
153
|
+
}
|
|
154
|
+
} // Bind log handler which normalizes args and populates meta
|
|
155
|
+
|
|
156
|
+
|
|
111
157
|
this[element] = function () {
|
|
112
158
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
113
159
|
args[_key] = arguments[_key];
|
|
@@ -115,28 +161,44 @@ class Axe {
|
|
|
115
161
|
|
|
116
162
|
return _this.log(element, ...Array.prototype.slice.call(args));
|
|
117
163
|
};
|
|
118
|
-
}
|
|
119
|
-
|
|
164
|
+
}
|
|
120
165
|
|
|
121
166
|
this.setLevel = this.setLevel.bind(this);
|
|
122
167
|
this.getNormalizedLevel = this.getNormalizedLevel.bind(this);
|
|
123
|
-
this.setName = this.setName.bind(this);
|
|
124
|
-
this.setCallback = this.setCallback.bind(this); // Set the logger name
|
|
168
|
+
this.setName = this.setName.bind(this); // Set the logger name
|
|
125
169
|
|
|
126
170
|
if (this.config.name) this.setName(this.config.name); // Set the logger level
|
|
127
171
|
|
|
128
172
|
this.setLevel(this.config.level); // Aliases
|
|
129
173
|
|
|
130
174
|
this.err = this.error;
|
|
131
|
-
this.warning = this.warn;
|
|
132
|
-
}
|
|
175
|
+
this.warning = this.warn; // Pre and Post Hooks
|
|
133
176
|
|
|
134
|
-
|
|
135
|
-
|
|
177
|
+
this.pre = function (level, fn) {
|
|
178
|
+
this.config.hooks.pre.push(function (_level) {
|
|
179
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
180
|
+
args[_key2 - 1] = arguments[_key2];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (level !== _level) return [...args];
|
|
184
|
+
return fn(...args);
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
this.post = function (level, fn) {
|
|
189
|
+
this.config.hooks.post.push(function (_level) {
|
|
190
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
191
|
+
args[_key3 - 1] = arguments[_key3];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (level !== _level) return [...args];
|
|
195
|
+
return fn(...args);
|
|
196
|
+
});
|
|
197
|
+
};
|
|
136
198
|
}
|
|
137
199
|
|
|
138
200
|
setLevel(level) {
|
|
139
|
-
if (!isString(level) ||
|
|
201
|
+
if (!isString(level) || levels.indexOf(level) === -1) throw new Error(levelError); // Support signale logger and other loggers that use `logLevel`
|
|
140
202
|
|
|
141
203
|
if (isString(this.config.logger.logLevel)) this.config.logger.logLevel = level;else this.config.logger.level = level; // Adjusts `this.config.levels` array
|
|
142
204
|
// so that it has all proceeding (inclusive)
|
|
@@ -147,7 +209,7 @@ class Axe {
|
|
|
147
209
|
getNormalizedLevel(level) {
|
|
148
210
|
if (!isString(level)) return 'info';
|
|
149
211
|
if (isString(aliases[level])) return aliases[level];
|
|
150
|
-
if (
|
|
212
|
+
if (levels.indexOf(level) === -1) return 'info';
|
|
151
213
|
return level;
|
|
152
214
|
}
|
|
153
215
|
|
|
@@ -160,12 +222,13 @@ class Axe {
|
|
|
160
222
|
|
|
161
223
|
log(level, message, meta) {
|
|
162
224
|
const originalArgs = [];
|
|
225
|
+
const errors = [];
|
|
163
226
|
if (!isUndefined(level)) originalArgs.push(level);
|
|
164
227
|
if (!isUndefined(message)) originalArgs.push(message);
|
|
165
228
|
if (!isUndefined(meta)) originalArgs.push(meta);
|
|
166
229
|
|
|
167
|
-
for (var
|
|
168
|
-
args[
|
|
230
|
+
for (var _len4 = arguments.length, args = new Array(_len4 > 3 ? _len4 - 3 : 0), _key4 = 3; _key4 < _len4; _key4++) {
|
|
231
|
+
args[_key4 - 3] = arguments[_key4];
|
|
169
232
|
}
|
|
170
233
|
|
|
171
234
|
for (const arg of Array.prototype.slice.call(args)) {
|
|
@@ -183,13 +246,15 @@ class Axe {
|
|
|
183
246
|
meta = message;
|
|
184
247
|
message = level;
|
|
185
248
|
level = 'error';
|
|
186
|
-
} else if (!isString(level) ||
|
|
249
|
+
} else if (!isString(level) || levels.indexOf(level) === -1) {
|
|
187
250
|
meta = message;
|
|
188
251
|
message = level;
|
|
189
252
|
level = this.getNormalizedLevel(level);
|
|
190
253
|
modifier = -1;
|
|
191
|
-
} //
|
|
254
|
+
} // Return early if it is not a valid logging level
|
|
255
|
+
|
|
192
256
|
|
|
257
|
+
if (config.levels.indexOf(level) === -1) return; // Bunyan support (meta, message, ...args)
|
|
193
258
|
|
|
194
259
|
let isBunyan = false;
|
|
195
260
|
|
|
@@ -210,11 +275,16 @@ class Axe {
|
|
|
210
275
|
};
|
|
211
276
|
message = level;
|
|
212
277
|
} else if (!isBunyan && originalArgs.length >= 4 + modifier) {
|
|
213
|
-
|
|
214
|
-
// then infer to use util.format on everything
|
|
215
|
-
message = format(...originalArgs.slice(1 + modifier));
|
|
278
|
+
message = undefined;
|
|
216
279
|
meta = {};
|
|
217
|
-
|
|
280
|
+
const messages = [];
|
|
281
|
+
|
|
282
|
+
for (const arg of originalArgs) {
|
|
283
|
+
if (isError(arg)) errors.push(arg);else if (isString(arg)) messages.push(arg);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (errors.length === 0 && messages.length > 0) message = format(...messages);else if (errors.length > 0 && level === 'log') level = 'error';
|
|
287
|
+
} else if (!isBunyan && originalArgs.length === 3 + modifier && isString(message) && formatSpecifiers.some(t => message.indexOf(t) !== -1)) {
|
|
218
288
|
// Otherwise if there are three args and if the `message` contains
|
|
219
289
|
// a placeholder token (e.g. '%s' or '%d' - see above `formatSpecifiers` variable)
|
|
220
290
|
// then we can infer that the `meta` arg passed is used for formatting
|
|
@@ -222,9 +292,8 @@ class Axe {
|
|
|
222
292
|
meta = {};
|
|
223
293
|
} else if (!isError(message)) {
|
|
224
294
|
if (isError(meta)) {
|
|
225
|
-
meta
|
|
226
|
-
|
|
227
|
-
}; // } else if (!isPlainObject(meta) && !isUndefined(meta) && !isNull(meta)) {
|
|
295
|
+
errors.push(meta);
|
|
296
|
+
meta = {};
|
|
228
297
|
} else if (!isObject(meta) && !isUndefined(meta) && !isNull(meta)) {
|
|
229
298
|
// If the `meta` variable passed was not an Object then convert it
|
|
230
299
|
message = format(message, meta);
|
|
@@ -235,65 +304,50 @@ class Axe {
|
|
|
235
304
|
// (as opposed to using something like fast-json-stringify)
|
|
236
305
|
message = format(message);
|
|
237
306
|
}
|
|
238
|
-
}
|
|
307
|
+
} else if (isError(meta)) {
|
|
308
|
+
errors.push(meta); // handle additional args
|
|
239
309
|
|
|
310
|
+
for (const arg of originalArgs.slice(2 + modifier)) {
|
|
311
|
+
// should skip this better with slice and modifier adjustment
|
|
312
|
+
if (meta === arg) continue;
|
|
313
|
+
if (isError(arg)) errors.push(arg);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
meta = {};
|
|
317
|
+
}
|
|
240
318
|
|
|
241
319
|
if (!isUndefined(meta) && !isObject(meta)) meta = {
|
|
242
|
-
meta
|
|
320
|
+
original_meta: meta
|
|
243
321
|
};else if (!isObject(meta)) meta = {};
|
|
244
|
-
const hadErrorInMeta = isObject(meta.err);
|
|
245
|
-
let error;
|
|
246
322
|
|
|
247
323
|
if (isError(message)) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
error = meta.err;
|
|
255
|
-
} // Omit `callback` from `meta` if it was passed
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const callback = isFunction(config.callback) && (!isBoolean(meta.callback) || meta.callback);
|
|
259
|
-
meta = omit(meta, ['callback']); // Set default level on meta
|
|
260
|
-
|
|
261
|
-
meta.level = level; // Add `app` object to metadata
|
|
262
|
-
|
|
263
|
-
if (this.appInfo) meta.app = this.appInfo; // Set the body used for returning with and sending logs
|
|
264
|
-
// (and also remove circular references)
|
|
265
|
-
|
|
266
|
-
const body = safeStringify({
|
|
267
|
-
message,
|
|
268
|
-
meta
|
|
269
|
-
}); // Send to Cabin or other logging service here the `message` and `meta`
|
|
324
|
+
errors.unshift(message);
|
|
325
|
+
message = undefined;
|
|
326
|
+
} //
|
|
327
|
+
// rewrite `meta.err` to `meta.original_err` for consistency
|
|
328
|
+
// (in case someone has an object with `.err` property on it with an error)
|
|
329
|
+
//
|
|
270
330
|
|
|
271
|
-
if (config.capture && config.levels.includes(level) && (!isError(error) || !error._captureFailed)) {
|
|
272
|
-
// If the user didn't specify a key
|
|
273
|
-
// and they are using the default endpoint
|
|
274
|
-
// then we should throw an error to them
|
|
275
|
-
if (config.endpoint === endpoint && !config.key) throw new Error("Cabin API key required (e.g. `{ key: 'YOUR-CABIN-API-KEY' })`)\n<https://cabinjs.com>"); // Capture the log over HTTP
|
|
276
331
|
|
|
277
|
-
|
|
278
|
-
if (
|
|
332
|
+
if (isObject(meta.err)) {
|
|
333
|
+
if (isError(meta.err)) errors.push(meta.err);
|
|
334
|
+
meta.original_err = isError(meta.err) ? parseErr(meta.err) : meta.err;
|
|
335
|
+
}
|
|
279
336
|
|
|
280
|
-
|
|
337
|
+
let err;
|
|
281
338
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
} // Custom callback function (e.g. Slack message)
|
|
339
|
+
if (errors.length > 0) {
|
|
340
|
+
err = combine(errors);
|
|
341
|
+
meta.err = parseErr(err);
|
|
342
|
+
if (!isString(message)) message = err.message;
|
|
343
|
+
} // Set `args` prop with original arguments passed
|
|
290
344
|
|
|
291
345
|
|
|
292
|
-
|
|
346
|
+
meta.args = originalArgs; // Set default level on meta
|
|
293
347
|
|
|
294
|
-
|
|
348
|
+
meta.level = level; // Add `app` object to metadata
|
|
295
349
|
|
|
296
|
-
if (
|
|
350
|
+
if (this.appInfo) meta.app = this.appInfo; //
|
|
297
351
|
// determine log method to use
|
|
298
352
|
//
|
|
299
353
|
// if we didn't pass a level as a method
|
|
@@ -303,27 +357,111 @@ class Axe {
|
|
|
303
357
|
// and fatal should use error (e.g. in browser)
|
|
304
358
|
//
|
|
305
359
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
//
|
|
360
|
+
const method = modifier === -1 ? 'log' : level; //
|
|
361
|
+
// NOTE: using lodash _.omit and _.pick would have been _very slow_
|
|
362
|
+
//
|
|
363
|
+
// const omittedAndPickedFields = {
|
|
364
|
+
// ..._.omit(meta, this.config.meta.omittedFields),
|
|
365
|
+
// ..._.pick(meta, this.config.meta.pickedFields)
|
|
366
|
+
// };
|
|
367
|
+
//
|
|
368
|
+
// also we don't want to mutate anything in `meta`
|
|
369
|
+
// and ideally we only want to pick exactly what we need
|
|
370
|
+
// (and not have two operations, one for omit, and one for pick)
|
|
371
|
+
//
|
|
372
|
+
|
|
373
|
+
if (!isEmpty(this.config.meta.remappedFields)) {
|
|
374
|
+
for (const key of Object.keys(this.config.meta.remappedFields)) {
|
|
375
|
+
set(meta, this.config.meta.remappedFields[key], get(meta, key));
|
|
376
|
+
unset(meta, key); // cleanup empty objects after remapping
|
|
377
|
+
|
|
378
|
+
if (this.config.meta.cleanupRemapping) {
|
|
379
|
+
const index = key.lastIndexOf('.');
|
|
380
|
+
if (index === -1) continue;
|
|
381
|
+
const parentKey = key.slice(0, index);
|
|
382
|
+
if (isEmpty(get(meta, parentKey))) unset(meta, parentKey);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (!isEmpty(this.config.meta.omittedFields) || !isEmpty(this.config.meta.pickedFields)) {
|
|
388
|
+
const dotified = dotifyToArray(meta); // dotified = [
|
|
389
|
+
// 'err.name',
|
|
390
|
+
// 'err.message',
|
|
391
|
+
// 'err.stack',
|
|
392
|
+
// 'level',
|
|
393
|
+
// 'app.name',
|
|
394
|
+
// 'app.version',
|
|
395
|
+
// 'app.node',
|
|
396
|
+
// 'app.hash',
|
|
397
|
+
// // ...
|
|
398
|
+
// ]
|
|
399
|
+
|
|
400
|
+
if (!isEmpty(this.config.meta.omittedFields)) {
|
|
401
|
+
for (const prop of this.config.meta.omittedFields) {
|
|
402
|
+
// <https://stackoverflow.com/a/9882349>
|
|
403
|
+
let i = dotified.length;
|
|
404
|
+
|
|
405
|
+
while (i--) {
|
|
406
|
+
if (dotified[i] === prop || dotified[i].indexOf(`${prop}.`) === 0) dotified.splice(i, 1);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (!isEmpty(this.config.meta.pickedFields)) {
|
|
412
|
+
for (const prop of this.config.meta.pickedFields) {
|
|
413
|
+
// response.headers.boop
|
|
414
|
+
// response.headers.beep
|
|
415
|
+
// response.body
|
|
416
|
+
// response.text
|
|
417
|
+
// response
|
|
418
|
+
//
|
|
419
|
+
// so we need to split by the first period and omit any keys from dotified starting with it
|
|
420
|
+
const index = prop.indexOf('.');
|
|
421
|
+
const key = prop.slice(0, index + 1);
|
|
309
422
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if (!hadErrorInMeta) omittedFields.push('err'); // Omit app is configured
|
|
423
|
+
if (index !== -1) {
|
|
424
|
+
let i = dotified.length;
|
|
313
425
|
|
|
314
|
-
|
|
315
|
-
|
|
426
|
+
while (i--) {
|
|
427
|
+
if (dotified[i].indexOf(key) === 0) dotified.splice(i, 1);
|
|
428
|
+
}
|
|
429
|
+
} // finally add it if it did not already exist
|
|
316
430
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
431
|
+
|
|
432
|
+
if (dotified.indexOf(prop) === -1) dotified.push(prop);
|
|
433
|
+
}
|
|
434
|
+
} // now we call pick-deep using the final array
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
meta = pickDeep(meta, dotified);
|
|
438
|
+
} // pre-hooks
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
for (const hook of this.config.hooks.pre) {
|
|
442
|
+
[err, message, meta] = hook(method, err, message, meta);
|
|
443
|
+
} // only invoke logger methods if it was not silent
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
if (!config.silent) {
|
|
447
|
+
// Show stack trace if necessary (along with any metadata)
|
|
448
|
+
if (isError(err) && config.showStack) {
|
|
449
|
+
if (!config.meta.show || isEmpty(meta)) {
|
|
450
|
+
this.config.logger[method](err);
|
|
451
|
+
} else {
|
|
452
|
+
this.config.logger[method](err, meta);
|
|
453
|
+
}
|
|
454
|
+
} else if (!config.meta.show || isEmpty(meta)) {
|
|
455
|
+
this.config.logger[method](message);
|
|
456
|
+
} else {
|
|
457
|
+
this.config.logger[method](message, meta);
|
|
458
|
+
}
|
|
459
|
+
} // post-hooks
|
|
324
460
|
|
|
325
461
|
|
|
326
|
-
|
|
462
|
+
pMapSeries(this.config.hooks.post, hook => hook(method, err, message, meta)).then().catch(err => {
|
|
463
|
+
this.config.logger.error(err);
|
|
464
|
+
});
|
|
327
465
|
}
|
|
328
466
|
|
|
329
467
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axe",
|
|
3
|
-
"description": "
|
|
4
|
-
"version": "
|
|
3
|
+
"description": "Axe is a logger-agnostic wrapper that normalizes logs regardless of argument style. Great for large development teams, old and new projects, and works with Pino, Bunyan, Winston, console, and more. It is lightweight, performant, highly-configurable, and automatically adds OS, CPU, and Git information to your logs. It supports hooks (useful for masking sensitive data) and dot-notation remapping, omitting, and picking of log metadata properties. Made for Forward Email, Lad, and Cabin.",
|
|
4
|
+
"version": "10.0.0",
|
|
5
5
|
"author": "Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com)",
|
|
6
6
|
"browser": {
|
|
7
7
|
"parse-app-info": false
|
|
@@ -11,20 +11,25 @@
|
|
|
11
11
|
},
|
|
12
12
|
"contributors": [
|
|
13
13
|
"Nick Baugh <niftylettuce@gmail.com> (http://niftylettuce.com)",
|
|
14
|
-
"Alexis Tyler <xo@wvvw.me> (https://wvvw.me/)"
|
|
14
|
+
"Alexis Tyler <xo@wvvw.me> (https://wvvw.me/)",
|
|
15
|
+
"shadowgate15 (https://github.com/shadowgate15)",
|
|
16
|
+
"Spencer Snyder <sasnyde2@gmail.com> (https://spencersnyder.io)"
|
|
15
17
|
],
|
|
16
18
|
"dependencies": {
|
|
17
19
|
"@ladjs/format-util": "^1.0.4",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
20
|
+
"@strikeentco/get": "1.0.1",
|
|
21
|
+
"@strikeentco/set": "1.0.2",
|
|
22
|
+
"boolean": "3.2.0",
|
|
23
|
+
"console-polyfill": "0.3.0",
|
|
22
24
|
"format-specifiers": "^1.0.0",
|
|
23
|
-
"iserror": "
|
|
24
|
-
"
|
|
25
|
+
"iserror": "0.0.2",
|
|
26
|
+
"maybe-combine-errors": "1.0.0",
|
|
27
|
+
"merge-options": "3.0.4",
|
|
28
|
+
"p-map-series": "2",
|
|
25
29
|
"parse-app-info": "^4.0.3",
|
|
26
30
|
"parse-err": "^0.0.12",
|
|
27
|
-
"
|
|
31
|
+
"pick-deep": "1.0.0",
|
|
32
|
+
"unset-value": "2.0.1"
|
|
28
33
|
},
|
|
29
34
|
"devDependencies": {
|
|
30
35
|
"@babel/cli": "^7.17.10",
|
|
@@ -111,16 +116,16 @@
|
|
|
111
116
|
},
|
|
112
117
|
"scripts": {
|
|
113
118
|
"ava": "cross-env NODE_ENV=test ava",
|
|
114
|
-
"browserify": "browserify src/index.js -o dist/axe.js -s Axe -g [ babelify --configFile ./.dist.babelrc ]",
|
|
119
|
+
"browserify": "browserify src/index.js -o dist/axe.js -s Axe -g [ babelify --configFile ./.dist.babelrc.json ]",
|
|
115
120
|
"build": "npm run build:clean && npm run build:lib && npm run build:dist",
|
|
116
121
|
"build:clean": "rimraf lib dist",
|
|
117
122
|
"build:dist": "npm run browserify && npm run minify",
|
|
118
|
-
"build:lib": "babel --config-file ./.lib.babelrc src --out-dir lib",
|
|
123
|
+
"build:lib": "babel --config-file ./.lib.babelrc.json src --out-dir lib",
|
|
119
124
|
"lint": "xo --fix && remark . -qfo && fixpack",
|
|
120
125
|
"lint-build": "npm run lint-lib && npm run lint-dist",
|
|
121
|
-
"lint-dist": "eslint --no-inline-config -c .dist.eslintrc dist",
|
|
122
|
-
"lint-lib": "eslint --no-inline-config -c .lib.eslintrc lib",
|
|
123
|
-
"minify": "cross-env NODE_ENV=production browserify src/index.js -o dist/axe.min.js -s Axe -g [ babelify --configFile ./.dist.babelrc ] -p tinyify",
|
|
126
|
+
"lint-dist": "eslint --no-inline-config -c .dist.eslintrc.json dist",
|
|
127
|
+
"lint-lib": "eslint --no-inline-config -c .lib.eslintrc.json lib",
|
|
128
|
+
"minify": "cross-env NODE_ENV=production browserify src/index.js -o dist/axe.min.js -s Axe -g [ babelify --configFile ./.dist.babelrc.json ] -p tinyify",
|
|
124
129
|
"nyc": "cross-env NODE_ENV=test nyc ava",
|
|
125
130
|
"prepare": "husky install",
|
|
126
131
|
"pretest": "npm run lint",
|