logmessage-cls-hooked
Version:
A LogRoot Method Decorator that uses cls-hooked to handle and propagate log message details between different methods deeper in the callstack, removing the need to propagate a paremeter just for logging purposes
26 lines (25 loc) • 904 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.appendOnLog = void 0;
var common_1 = require("./common");
/**
* Adds a new value to a key to the current active log context
* If the value already holds a array, it appends a new item
* If the value is not yet a array, it's converted into one
* If the value has never been sets, it's get initialized
* @param {string} key
* @param {string | number | boolean | Date} value
*/
var appendOnLog = function (key, value) {
var _a;
var session = (0, common_1._getSessionOrFail)();
var existingValue = (_a = session.get(key)) !== null && _a !== void 0 ? _a : [];
if (Array.isArray(existingValue)) {
session.set(key, existingValue.concat([value]));
}
else {
session.set(key, [value]);
}
(0, common_1._setPropKeyHistory)(session, key);
};
exports.appendOnLog = appendOnLog;
;