@salesforce/core
Version:
Core libraries to interact with SFDX projects, orgs, and APIs.
57 lines • 2.4 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
/*
* Copyright (c) 2023, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
const node_stream_1 = require("node:stream");
const unwrapArray_1 = require("../util/unwrapArray");
const filters_1 = require("./filters");
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
const build = require('pino-abstract-transport');
function default_1() {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
return build(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(source) => {
const myTransportStream = new node_stream_1.Transform({
objectMode: true,
transform(chunk, enc, cb) {
if (debugAllows(chunk)) {
// uses the original logger's filters.
const filteredChunk = (0, unwrapArray_1.unwrapArray)((0, filters_1.filterSecrets)([chunk]));
const stringified = JSON.stringify(filteredChunk);
this.push(stringified.concat('\n'));
}
cb();
},
});
// eslint-disable-next-line @typescript-eslint/no-empty-function
(0, node_stream_1.pipeline)(source, myTransportStream, () => { });
return myTransportStream;
}, {
// This is needed to be able to pipeline transports.
enablePipelining: true,
});
}
/** if the DEBUG= is set, see if that matches the logger name. If not, we don't want to keep going */
const debugAllows = (chunk) => {
if (!process.env.DEBUG || process.env.DEBUG === '*')
return true;
if (typeof chunk.name !== 'string')
return true;
// turn wildcard patterns into regexes
const regexFromDebug = new RegExp(process.env.DEBUG.replace(/\*/g, '.*'));
if (!regexFromDebug.test(chunk.name)) {
// console.log(`no match : ${chunk.name} for ${process.env.DEBUG}`);
return false;
}
else {
// console.log(`match : ${chunk.name} for ${process.env.DEBUG}`);
return true;
}
};
//# sourceMappingURL=transformStream.js.map
;