infront-logger 1.1.2 → 1.1.3
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/dist/index.es.js +21 -4
- package/dist/index.umd.js +21 -4
- package/package.json +1 -1
package/dist/index.es.js
CHANGED
|
@@ -392,9 +392,14 @@ const ops = [
|
|
|
392
392
|
"aggregate",
|
|
393
393
|
"save"
|
|
394
394
|
];
|
|
395
|
+
const explained = [
|
|
396
|
+
"find",
|
|
397
|
+
"findOne"
|
|
398
|
+
];
|
|
395
399
|
const OPTIONS = {
|
|
396
400
|
maxResBytes: 100 * 1024,
|
|
397
|
-
logRes: true
|
|
401
|
+
logRes: true,
|
|
402
|
+
explain: false
|
|
398
403
|
};
|
|
399
404
|
class MongooseLogger extends BaseLogger {
|
|
400
405
|
constructor(options = {}) {
|
|
@@ -420,9 +425,15 @@ class MongooseLogger extends BaseLogger {
|
|
|
420
425
|
this.ctx.pipeline = p;
|
|
421
426
|
return this;
|
|
422
427
|
}
|
|
428
|
+
async explain(query) {
|
|
429
|
+
if (this.options.explain && !query.options.explain) {
|
|
430
|
+
this.ctx.explain = await query.clone().explain();
|
|
431
|
+
}
|
|
432
|
+
}
|
|
423
433
|
result(res) {
|
|
424
434
|
try {
|
|
425
435
|
this.ctx.resultSizeBytes = JSON.stringify(res).length;
|
|
436
|
+
this.ctx.resultLength = Array.isArray(res) ? res.length : res ? 1 : 0;
|
|
426
437
|
} catch (err) {
|
|
427
438
|
}
|
|
428
439
|
if (!this.options.logRes)
|
|
@@ -437,11 +448,17 @@ class MongooseLogger extends BaseLogger {
|
|
|
437
448
|
return this;
|
|
438
449
|
}
|
|
439
450
|
}
|
|
440
|
-
function postHook(target, res) {
|
|
441
|
-
var _a, _b, _c, _d, _e;
|
|
451
|
+
async function postHook(target, res) {
|
|
452
|
+
var _a, _b, _c, _d, _e, _f;
|
|
453
|
+
if (target.options.explain)
|
|
454
|
+
return;
|
|
442
455
|
const op = target.constructor.name === "Aggregate" ? "aggregate" : target.op || target.$op;
|
|
443
456
|
const collection = ((_a = target == null ? void 0 : target._collection) == null ? void 0 : _a.collectionName) || ((_b = target == null ? void 0 : target.collection) == null ? void 0 : _b.name) || ((_d = (_c = target == null ? void 0 : target._model) == null ? void 0 : _c.collection) == null ? void 0 : _d.collectionName);
|
|
444
|
-
(_e = target == null ? void 0 : target.logger) == null ? void 0 : _e.operation(op).collection(collection).query(target._conditions).update(target._update).pipeline(target._pipeline).profile().result(res)
|
|
457
|
+
(_e = target == null ? void 0 : target.logger) == null ? void 0 : _e.operation(op).collection(collection).query(target._conditions).update(target._update).pipeline(target._pipeline).profile().result(res);
|
|
458
|
+
if (explained.includes(op)) {
|
|
459
|
+
await (target == null ? void 0 : target.logger.explain(target));
|
|
460
|
+
}
|
|
461
|
+
(_f = target == null ? void 0 : target.logger) == null ? void 0 : _f.info(`DB query: ${op} - ${collection}`);
|
|
445
462
|
}
|
|
446
463
|
function plugin(options = {}) {
|
|
447
464
|
return (schema) => {
|
package/dist/index.umd.js
CHANGED
|
@@ -396,9 +396,14 @@
|
|
|
396
396
|
"aggregate",
|
|
397
397
|
"save"
|
|
398
398
|
];
|
|
399
|
+
const explained = [
|
|
400
|
+
"find",
|
|
401
|
+
"findOne"
|
|
402
|
+
];
|
|
399
403
|
const OPTIONS = {
|
|
400
404
|
maxResBytes: 100 * 1024,
|
|
401
|
-
logRes: true
|
|
405
|
+
logRes: true,
|
|
406
|
+
explain: false
|
|
402
407
|
};
|
|
403
408
|
class MongooseLogger extends BaseLogger {
|
|
404
409
|
constructor(options = {}) {
|
|
@@ -424,9 +429,15 @@
|
|
|
424
429
|
this.ctx.pipeline = p;
|
|
425
430
|
return this;
|
|
426
431
|
}
|
|
432
|
+
async explain(query) {
|
|
433
|
+
if (this.options.explain && !query.options.explain) {
|
|
434
|
+
this.ctx.explain = await query.clone().explain();
|
|
435
|
+
}
|
|
436
|
+
}
|
|
427
437
|
result(res) {
|
|
428
438
|
try {
|
|
429
439
|
this.ctx.resultSizeBytes = JSON.stringify(res).length;
|
|
440
|
+
this.ctx.resultLength = Array.isArray(res) ? res.length : res ? 1 : 0;
|
|
430
441
|
} catch (err) {
|
|
431
442
|
}
|
|
432
443
|
if (!this.options.logRes)
|
|
@@ -441,11 +452,17 @@
|
|
|
441
452
|
return this;
|
|
442
453
|
}
|
|
443
454
|
}
|
|
444
|
-
function postHook(target, res) {
|
|
445
|
-
var _a, _b, _c, _d, _e;
|
|
455
|
+
async function postHook(target, res) {
|
|
456
|
+
var _a, _b, _c, _d, _e, _f;
|
|
457
|
+
if (target.options.explain)
|
|
458
|
+
return;
|
|
446
459
|
const op = target.constructor.name === "Aggregate" ? "aggregate" : target.op || target.$op;
|
|
447
460
|
const collection = ((_a = target == null ? void 0 : target._collection) == null ? void 0 : _a.collectionName) || ((_b = target == null ? void 0 : target.collection) == null ? void 0 : _b.name) || ((_d = (_c = target == null ? void 0 : target._model) == null ? void 0 : _c.collection) == null ? void 0 : _d.collectionName);
|
|
448
|
-
(_e = target == null ? void 0 : target.logger) == null ? void 0 : _e.operation(op).collection(collection).query(target._conditions).update(target._update).pipeline(target._pipeline).profile().result(res)
|
|
461
|
+
(_e = target == null ? void 0 : target.logger) == null ? void 0 : _e.operation(op).collection(collection).query(target._conditions).update(target._update).pipeline(target._pipeline).profile().result(res);
|
|
462
|
+
if (explained.includes(op)) {
|
|
463
|
+
await (target == null ? void 0 : target.logger.explain(target));
|
|
464
|
+
}
|
|
465
|
+
(_f = target == null ? void 0 : target.logger) == null ? void 0 : _f.info(`DB query: ${op} - ${collection}`);
|
|
449
466
|
}
|
|
450
467
|
function plugin(options = {}) {
|
|
451
468
|
return (schema) => {
|