mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 12:21:24 +00:00
fix(ui): unblock docker onboarding build
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { createRequire } from "node:module";
|
||||
import util from "node:util";
|
||||
import type { OpenClawConfig } from "../config/types.js";
|
||||
import { isVerbose } from "../globals.js";
|
||||
@@ -16,14 +15,37 @@ type ConsoleSettings = {
|
||||
};
|
||||
export type ConsoleLoggerSettings = ConsoleSettings;
|
||||
|
||||
const requireConfig = createRequire(import.meta.url);
|
||||
function resolveNodeRequire(): ((id: string) => NodeJS.Require) | null {
|
||||
const getBuiltinModule = (
|
||||
process as NodeJS.Process & {
|
||||
getBuiltinModule?: (id: string) => unknown;
|
||||
}
|
||||
).getBuiltinModule;
|
||||
if (typeof getBuiltinModule !== "function") {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const moduleNamespace = getBuiltinModule("module") as {
|
||||
createRequire?: (id: string) => NodeJS.Require;
|
||||
};
|
||||
return typeof moduleNamespace.createRequire === "function"
|
||||
? moduleNamespace.createRequire
|
||||
: null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const requireConfig = resolveNodeRequire()?.(import.meta.url) ?? null;
|
||||
type ConsoleConfigLoader = () => OpenClawConfig["logging"] | undefined;
|
||||
const loadConfigFallbackDefault: ConsoleConfigLoader = () => {
|
||||
try {
|
||||
const loaded = requireConfig("../config/config.js") as {
|
||||
loadConfig?: () => OpenClawConfig;
|
||||
};
|
||||
return loaded.loadConfig?.().logging;
|
||||
const loaded = requireConfig?.("../config/config.js") as
|
||||
| {
|
||||
loadConfig?: () => OpenClawConfig;
|
||||
}
|
||||
| undefined;
|
||||
return loaded?.loadConfig?.().logging;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import fs from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import path from "node:path";
|
||||
import { Logger as TsLogger } from "tslog";
|
||||
import type { OpenClawConfig } from "../config/types.js";
|
||||
@@ -16,7 +15,28 @@ const LOG_PREFIX = "openclaw";
|
||||
const LOG_SUFFIX = ".log";
|
||||
const MAX_LOG_AGE_MS = 24 * 60 * 60 * 1000; // 24h
|
||||
|
||||
const requireConfig = createRequire(import.meta.url);
|
||||
function resolveNodeRequire(): ((id: string) => NodeJS.Require) | null {
|
||||
const getBuiltinModule = (
|
||||
process as NodeJS.Process & {
|
||||
getBuiltinModule?: (id: string) => unknown;
|
||||
}
|
||||
).getBuiltinModule;
|
||||
if (typeof getBuiltinModule !== "function") {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const moduleNamespace = getBuiltinModule("module") as {
|
||||
createRequire?: (id: string) => NodeJS.Require;
|
||||
};
|
||||
return typeof moduleNamespace.createRequire === "function"
|
||||
? moduleNamespace.createRequire
|
||||
: null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const requireConfig = resolveNodeRequire()?.(import.meta.url) ?? null;
|
||||
|
||||
export type LoggerSettings = {
|
||||
level?: LogLevel;
|
||||
@@ -55,10 +75,12 @@ function resolveSettings(): ResolvedSettings {
|
||||
(loggingState.overrideSettings as LoggerSettings | null) ?? readLoggingConfig();
|
||||
if (!cfg) {
|
||||
try {
|
||||
const loaded = requireConfig("../config/config.js") as {
|
||||
loadConfig?: () => OpenClawConfig;
|
||||
};
|
||||
cfg = loaded.loadConfig?.().logging;
|
||||
const loaded = requireConfig?.("../config/config.js") as
|
||||
| {
|
||||
loadConfig?: () => OpenClawConfig;
|
||||
}
|
||||
| undefined;
|
||||
cfg = loaded?.loadConfig?.().logging;
|
||||
} catch {
|
||||
cfg = undefined;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,27 @@
|
||||
import { createRequire } from "node:module";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
|
||||
const requireConfig = createRequire(import.meta.url);
|
||||
function resolveNodeRequire(): ((id: string) => NodeJS.Require) | null {
|
||||
const getBuiltinModule = (
|
||||
process as NodeJS.Process & {
|
||||
getBuiltinModule?: (id: string) => unknown;
|
||||
}
|
||||
).getBuiltinModule;
|
||||
if (typeof getBuiltinModule !== "function") {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const moduleNamespace = getBuiltinModule("module") as {
|
||||
createRequire?: (id: string) => NodeJS.Require;
|
||||
};
|
||||
return typeof moduleNamespace.createRequire === "function"
|
||||
? moduleNamespace.createRequire
|
||||
: null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const requireConfig = resolveNodeRequire()?.(import.meta.url) ?? null;
|
||||
|
||||
export type RedactSensitiveMode = "off" | "tools";
|
||||
|
||||
@@ -110,10 +130,12 @@ function redactText(text: string, patterns: RegExp[]): string {
|
||||
function resolveConfigRedaction(): RedactOptions {
|
||||
let cfg: OpenClawConfig["logging"] | undefined;
|
||||
try {
|
||||
const loaded = requireConfig("../config/config.js") as {
|
||||
loadConfig?: () => OpenClawConfig;
|
||||
};
|
||||
cfg = loaded.loadConfig?.().logging;
|
||||
const loaded = requireConfig?.("../config/config.js") as
|
||||
| {
|
||||
loadConfig?: () => OpenClawConfig;
|
||||
}
|
||||
| undefined;
|
||||
cfg = loaded?.loadConfig?.().logging;
|
||||
} catch {
|
||||
cfg = undefined;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { inspect } from "node:util";
|
||||
import { Chalk } from "chalk";
|
||||
import type { Logger as TsLogger } from "tslog";
|
||||
import { CHAT_CHANNEL_ORDER } from "../channels/registry.js";
|
||||
@@ -36,6 +35,39 @@ function shouldLogToConsole(level: LogLevel, settings: { level: LogLevel }): boo
|
||||
|
||||
type ChalkInstance = InstanceType<typeof Chalk>;
|
||||
|
||||
const inspectValue: ((value: unknown) => string) | null = (() => {
|
||||
const getBuiltinModule = (
|
||||
process as NodeJS.Process & {
|
||||
getBuiltinModule?: (id: string) => unknown;
|
||||
}
|
||||
).getBuiltinModule;
|
||||
if (typeof getBuiltinModule !== "function") {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const utilNamespace = getBuiltinModule("util") as {
|
||||
inspect?: (value: unknown) => string;
|
||||
};
|
||||
return typeof utilNamespace.inspect === "function" ? utilNamespace.inspect : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
})();
|
||||
|
||||
function formatRuntimeArg(arg: unknown): string {
|
||||
if (typeof arg === "string") {
|
||||
return arg;
|
||||
}
|
||||
if (inspectValue) {
|
||||
return inspectValue(arg);
|
||||
}
|
||||
try {
|
||||
return JSON.stringify(arg);
|
||||
} catch {
|
||||
return String(arg);
|
||||
}
|
||||
}
|
||||
|
||||
function isRichConsoleEnv(): boolean {
|
||||
const term = (process.env.TERM ?? "").toLowerCase();
|
||||
if (process.env.COLORTERM || process.env.TERM_PROGRAM) {
|
||||
@@ -323,7 +355,7 @@ export function runtimeForLogger(
|
||||
): RuntimeEnv {
|
||||
const formatArgs = (...args: unknown[]) =>
|
||||
args
|
||||
.map((arg) => (typeof arg === "string" ? arg : inspect(arg)))
|
||||
.map((arg) => formatRuntimeArg(arg))
|
||||
.join(" ")
|
||||
.trim();
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user