actionhero
Version:
actionhero.js is a multi-transport API Server with integrated cluster capabilities and delayed tasks
33 lines (32 loc) • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.filterObjectForLogging = void 0;
const isPlainObject_1 = require("./isPlainObject");
const config_1 = require("../config");
const dotProp = require("dot-prop");
/**
* Prepares acton params for logging.
* Hides any sensitive data as defined by `api.config.general.filteredParams`
* Truncates long strings via `api.config.logger.maxLogStringLength`
*/
function filterObjectForLogging(params) {
const filteredParams = {};
for (const i in params) {
if (isPlainObject_1.isPlainObject(params[i])) {
filteredParams[i] = Object.assign({}, params[i]);
}
else if (typeof params[i] === "string") {
filteredParams[i] = params[i].substring(0, config_1.config.logger.maxLogStringLength);
}
else {
filteredParams[i] = params[i];
}
}
config_1.config.general.filteredParams.forEach((configParam) => {
if (dotProp.get(params, configParam) !== undefined) {
dotProp.set(filteredParams, configParam, "[FILTERED]");
}
});
return filteredParams;
}
exports.filterObjectForLogging = filterObjectForLogging;