41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.logJson = logJson;
|
|
const REDACT_KEYS = new Set(["apiKey", "authorization", "Authorization", "openai_api_key", "OPENAI_API_KEY"]);
|
|
function redactObject(value) {
|
|
if (Array.isArray(value)) {
|
|
return value.map(redactObject);
|
|
}
|
|
if (value !== null && typeof value === "object") {
|
|
const source = value;
|
|
const out = {};
|
|
for (const [key, field] of Object.entries(source)) {
|
|
if (REDACT_KEYS.has(key)) {
|
|
out[key] = "***REDACTED***";
|
|
}
|
|
else {
|
|
out[key] = redactObject(field);
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
return value;
|
|
}
|
|
function logJson(entry) {
|
|
const safe = {
|
|
...entry,
|
|
details: redactObject(entry.details)
|
|
};
|
|
// Structured JSON logs for diagnostics/trace aggregation.
|
|
try {
|
|
process.stdout.write(JSON.stringify(safe) + "\n");
|
|
}
|
|
catch (error) {
|
|
const code = error?.code;
|
|
if (code === "ENOSPC" || code === "EPIPE") {
|
|
return;
|
|
}
|
|
throw error;
|
|
}
|
|
}
|