openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
35 lines (34 loc) • 1.77 kB
JavaScript
import { n as loggingState } from "./state-UxwJeH7V.js";
import { p as redactSensitiveText, y as readLoggingConfig } from "./redact-BtvPPfTi.js";
import { n as formatTimestamp } from "./timestamps-CD_Oo5x3.js";
import { stripVTControlCharacters } from "node:util";
//#region src/logging/json-console-line.ts
function formatJsonConsoleLine(params) {
const envelope = {
...params.meta,
time: formatTimestamp(/* @__PURE__ */ new Date(), { style: "long" }),
level: params.level,
...params.subsystem ? { subsystem: params.subsystem } : {},
message: params.message
};
const serialized = JSON.stringify(envelope, function(key, value) {
const isStructuralField = this === envelope && (key === "time" || key === "level");
return typeof value === "string" && !isStructuralField ? redactSensitiveText(value) : value;
});
return redactSensitiveText(serialized);
}
/** Formats diagnostics that must bypass console capture without bypassing JSON console style. */
function formatConsoleDiagnosticLine(params) {
return (loggingState.overrideSettings?.consoleStyle ?? readLoggingConfig()?.consoleStyle) === "json" ? formatJsonConsoleLine(params) : params.message;
}
/** Preserves human diagnostic blocks while serializing the whole block as one JSONL record. */
function formatConsoleDiagnosticBlock(params) {
if ((loggingState.overrideSettings?.consoleStyle ?? readLoggingConfig()?.consoleStyle) !== "json") return params.message;
const trailingNewline = params.message.endsWith("\n") ? "\n" : "";
return `${formatJsonConsoleLine({
level: params.level,
message: stripVTControlCharacters(params.message).trimEnd()
})}${trailingNewline}`;
}
//#endregion
export { formatConsoleDiagnosticLine as n, formatJsonConsoleLine as r, formatConsoleDiagnosticBlock as t };