mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 23:41:24 +00:00
refactor(logging): migrate non-agent internal console calls to subsystem logger (#22964)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: b4a5b12422
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
committed by
GitHub
parent
4ef4aa3c10
commit
2f46308d5a
@@ -2,10 +2,12 @@ import {
|
||||
filterBootstrapFilesForSession,
|
||||
loadExtraBootstrapFiles,
|
||||
} from "../../../agents/workspace.js";
|
||||
import { createSubsystemLogger } from "../../../logging/subsystem.js";
|
||||
import { resolveHookConfig } from "../../config.js";
|
||||
import { isAgentBootstrapEvent, type HookHandler } from "../../hooks.js";
|
||||
|
||||
const HOOK_KEY = "bootstrap-extra-files";
|
||||
const log = createSubsystemLogger("bootstrap-extra-files");
|
||||
|
||||
function normalizeStringArray(value: unknown): string[] {
|
||||
if (!Array.isArray(value)) {
|
||||
@@ -52,7 +54,7 @@ const bootstrapExtraFilesHook: HookHandler = async (event) => {
|
||||
context.sessionKey,
|
||||
);
|
||||
} catch (err) {
|
||||
console.warn(`[bootstrap-extra-files] failed: ${String(err)}`);
|
||||
log.warn(`failed: ${String(err)}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -27,8 +27,11 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { resolveStateDir } from "../../../config/paths.js";
|
||||
import { createSubsystemLogger } from "../../../logging/subsystem.js";
|
||||
import type { HookHandler } from "../../hooks.js";
|
||||
|
||||
const log = createSubsystemLogger("command-logger");
|
||||
|
||||
/**
|
||||
* Log all command events to a file
|
||||
*/
|
||||
@@ -57,10 +60,8 @@ const logCommand: HookHandler = async (event) => {
|
||||
|
||||
await fs.appendFile(logFile, logLine, "utf-8");
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"[command-logger] Failed to log command:",
|
||||
err instanceof Error ? err.message : String(err),
|
||||
);
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
log.error(`Failed to log command: ${message}`);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import type { WorkspaceBootstrapFile } from "../agents/workspace.js";
|
||||
import type { CliDeps } from "../cli/deps.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
|
||||
export type InternalHookEventType = "command" | "session" | "agent" | "gateway" | "message";
|
||||
|
||||
@@ -111,6 +112,7 @@ export type InternalHookHandler = (event: InternalHookEvent) => Promise<void> |
|
||||
|
||||
/** Registry of hook handlers by event key */
|
||||
const handlers = new Map<string, InternalHookHandler[]>();
|
||||
const log = createSubsystemLogger("internal-hooks");
|
||||
|
||||
/**
|
||||
* Register a hook handler for a specific event type or event:action combination
|
||||
@@ -201,10 +203,8 @@ export async function triggerInternalHook(event: InternalHookEvent): Promise<voi
|
||||
try {
|
||||
await handler(event);
|
||||
} catch (err) {
|
||||
console.error(
|
||||
`Hook error [${event.type}:${event.action}]:`,
|
||||
err instanceof Error ? err.message : String(err),
|
||||
);
|
||||
const message = err instanceof Error ? err.message : String(err);
|
||||
log.error(`Hook error [${event.type}:${event.action}]: ${message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ import {
|
||||
} from "../agents/agent-scope.js";
|
||||
import { runEmbeddedPiAgent } from "../agents/pi-embedded.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
|
||||
const log = createSubsystemLogger("llm-slug-generator");
|
||||
|
||||
/**
|
||||
* Generate a short 1-2 word filename slug from session content using LLM
|
||||
@@ -70,7 +73,8 @@ Reply with ONLY the slug, nothing else. Examples: "vendor-pitch", "api-design",
|
||||
|
||||
return null;
|
||||
} catch (err) {
|
||||
console.error("[llm-slug-generator] Failed to generate slug:", err);
|
||||
const message = err instanceof Error ? (err.stack ?? err.message) : String(err);
|
||||
log.error(`Failed to generate slug: ${message}`);
|
||||
return null;
|
||||
} finally {
|
||||
// Clean up temporary session file
|
||||
|
||||
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { MANIFEST_KEY } from "../compat/legacy-names.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
import { isPathInsideWithRealpath } from "../security/scan-paths.js";
|
||||
import { CONFIG_DIR, resolveUserPath } from "../utils.js";
|
||||
import { resolveBundledHooksDir } from "./bundled-dir.js";
|
||||
@@ -23,6 +24,7 @@ import type {
|
||||
type HookPackageManifest = {
|
||||
name?: string;
|
||||
} & Partial<Record<typeof MANIFEST_KEY, { hooks?: string[] }>>;
|
||||
const log = createSubsystemLogger("hooks/workspace");
|
||||
|
||||
function filterHookEntries(
|
||||
entries: HookEntry[],
|
||||
@@ -95,7 +97,7 @@ function loadHookFromDir(params: {
|
||||
}
|
||||
|
||||
if (!handlerPath) {
|
||||
console.warn(`[hooks] Hook "${name}" has HOOK.md but no handler file in ${params.hookDir}`);
|
||||
log.warn(`Hook "${name}" has HOOK.md but no handler file in ${params.hookDir}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -109,7 +111,8 @@ function loadHookFromDir(params: {
|
||||
handlerPath,
|
||||
};
|
||||
} catch (err) {
|
||||
console.warn(`[hooks] Failed to load hook from ${params.hookDir}:`, err);
|
||||
const message = err instanceof Error ? (err.stack ?? err.message) : String(err);
|
||||
log.warn(`Failed to load hook from ${params.hookDir}: ${message}`);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -145,8 +148,8 @@ function loadHooksFromDir(params: { dir: string; source: HookSource; pluginId?:
|
||||
for (const hookPath of packageHooks) {
|
||||
const resolvedHookDir = resolveContainedDir(hookDir, hookPath);
|
||||
if (!resolvedHookDir) {
|
||||
console.warn(
|
||||
`[hooks] Ignoring out-of-package hook path "${hookPath}" in ${hookDir} (must be within package directory)`,
|
||||
log.warn(
|
||||
`Ignoring out-of-package hook path "${hookPath}" in ${hookDir} (must be within package directory)`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user