Files
openclaw/src/config/logging.ts
Peter Steinberger de1dfab03e refactor: move terminal core into package (#88279)
* refactor: move terminal core into package

* refactor: move terminal module files

* fix: clean terminal package CI followups

* test: update lint suppression allowlist

* fix: ship terminal core runtime aliases
2026-05-30 11:07:45 +02:00

34 lines
1.2 KiB
TypeScript

import fs from "node:fs";
import { theme } from "../../packages/terminal-core/src/theme.js";
import type { RuntimeEnv } from "../runtime.js";
import { displayPath } from "../utils.js";
import { createConfigIO } from "./io.js";
type LogConfigUpdatedOptions = {
path?: string;
backupPath?: string | false;
suffix?: string;
};
export function formatConfigPath(path: string = createConfigIO().configPath): string {
return displayPath(path);
}
export function formatConfigUpdatedMessage(
path: string,
opts: LogConfigUpdatedOptions = {},
): string {
const displayConfigPath = theme.muted(formatConfigPath(path));
const suffix = opts.suffix ? ` ${opts.suffix}` : "";
const backupPath = opts.backupPath === undefined ? `${path}.bak` : opts.backupPath;
const lines = [`Updated config: ${displayConfigPath}${suffix}`];
if (backupPath && fs.existsSync(backupPath)) {
lines.push(` Backup: ${theme.muted(formatConfigPath(backupPath))}`);
}
return lines.join("\n");
}
export function logConfigUpdated(runtime: RuntimeEnv, opts: LogConfigUpdatedOptions = {}): void {
runtime.log(formatConfigUpdatedMessage(opts.path ?? createConfigIO().configPath, opts));
}