mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 02:11:36 +00:00
fix: log env opts and collapse duplicate blocks
This commit is contained in:
@@ -1,5 +1,32 @@
|
||||
import { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
import { parseBooleanValue } from "../utils/boolean.js";
|
||||
|
||||
const log = createSubsystemLogger("env");
|
||||
const loggedEnv = new Set<string>();
|
||||
|
||||
type AcceptedEnvOption = {
|
||||
key: string;
|
||||
description: string;
|
||||
value?: string;
|
||||
redact?: boolean;
|
||||
};
|
||||
|
||||
function formatEnvValue(value: string, redact?: boolean): string {
|
||||
if (redact) return "<redacted>";
|
||||
const singleLine = value.replace(/\s+/g, " ").trim();
|
||||
if (singleLine.length <= 160) return singleLine;
|
||||
return `${singleLine.slice(0, 160)}…`;
|
||||
}
|
||||
|
||||
export function logAcceptedEnvOption(option: AcceptedEnvOption): void {
|
||||
if (process.env.VITEST || process.env.NODE_ENV === "test") return;
|
||||
if (loggedEnv.has(option.key)) return;
|
||||
const rawValue = option.value ?? process.env[option.key];
|
||||
if (!rawValue || !rawValue.trim()) return;
|
||||
loggedEnv.add(option.key);
|
||||
log.info(`env: ${option.key}=${formatEnvValue(rawValue, option.redact)} (${option.description})`);
|
||||
}
|
||||
|
||||
export function normalizeZaiEnv(): void {
|
||||
if (!process.env.ZAI_API_KEY?.trim() && process.env.Z_AI_API_KEY?.trim()) {
|
||||
process.env.ZAI_API_KEY = process.env.Z_AI_API_KEY;
|
||||
|
||||
Reference in New Issue
Block a user