diff --git a/src/commands/onboarding/plugin-install.ts b/src/commands/onboarding/plugin-install.ts index 9550f9082f..6f5f6b9e56 100644 --- a/src/commands/onboarding/plugin-install.ts +++ b/src/commands/onboarding/plugin-install.ts @@ -8,6 +8,7 @@ import { enablePluginInConfig } from "../../plugins/enable.js"; import { installPluginFromNpmSpec } from "../../plugins/install.js"; import { recordPluginInstall } from "../../plugins/installs.js"; import { loadOpenClawPlugins } from "../../plugins/loader.js"; +import { createPluginLoaderLogger } from "../../plugins/logger.js"; import type { RuntimeEnv } from "../../runtime.js"; import type { WizardPrompter } from "../../wizard/prompts.js"; @@ -211,11 +212,6 @@ export function reloadOnboardingPluginRegistry(params: { config: params.cfg, workspaceDir, cache: false, - logger: { - info: (msg) => log.info(msg), - warn: (msg) => log.warn(msg), - error: (msg) => log.error(msg), - debug: (msg) => log.debug(msg), - }, + logger: createPluginLoaderLogger(log), }); } diff --git a/src/plugins/logger.test.ts b/src/plugins/logger.test.ts new file mode 100644 index 0000000000..cf1d773a9d --- /dev/null +++ b/src/plugins/logger.test.ts @@ -0,0 +1,22 @@ +import { describe, expect, it, vi } from "vitest"; +import { createPluginLoaderLogger } from "./logger.js"; + +describe("plugins/logger", () => { + it("forwards logger methods", () => { + const info = vi.fn(); + const warn = vi.fn(); + const error = vi.fn(); + const debug = vi.fn(); + const logger = createPluginLoaderLogger({ info, warn, error, debug }); + + logger.info("i"); + logger.warn("w"); + logger.error("e"); + logger.debug?.("d"); + + expect(info).toHaveBeenCalledWith("i"); + expect(warn).toHaveBeenCalledWith("w"); + expect(error).toHaveBeenCalledWith("e"); + expect(debug).toHaveBeenCalledWith("d"); + }); +}); diff --git a/src/plugins/logger.ts b/src/plugins/logger.ts new file mode 100644 index 0000000000..ea1a92deac --- /dev/null +++ b/src/plugins/logger.ts @@ -0,0 +1,17 @@ +import type { PluginLogger } from "./types.js"; + +type LoggerLike = { + info: (message: string) => void; + warn: (message: string) => void; + error: (message: string) => void; + debug?: (message: string) => void; +}; + +export function createPluginLoaderLogger(logger: LoggerLike): PluginLogger { + return { + info: (msg) => logger.info(msg), + warn: (msg) => logger.warn(msg), + error: (msg) => logger.error(msg), + debug: (msg) => logger.debug?.(msg), + }; +} diff --git a/src/plugins/providers.ts b/src/plugins/providers.ts index 7ab2d1848e..60d54d321b 100644 --- a/src/plugins/providers.ts +++ b/src/plugins/providers.ts @@ -1,5 +1,6 @@ import { createSubsystemLogger } from "../logging/subsystem.js"; import { loadOpenClawPlugins, type PluginLoadOptions } from "./loader.js"; +import { createPluginLoaderLogger } from "./logger.js"; import type { ProviderPlugin } from "./types.js"; const log = createSubsystemLogger("plugins"); @@ -11,12 +12,7 @@ export function resolvePluginProviders(params: { const registry = loadOpenClawPlugins({ config: params.config, workspaceDir: params.workspaceDir, - logger: { - info: (msg) => log.info(msg), - warn: (msg) => log.warn(msg), - error: (msg) => log.error(msg), - debug: (msg) => log.debug(msg), - }, + logger: createPluginLoaderLogger(log), }); return registry.providers.map((entry) => entry.provider); diff --git a/src/plugins/status.ts b/src/plugins/status.ts index b5d444cc3b..b136366eb4 100644 --- a/src/plugins/status.ts +++ b/src/plugins/status.ts @@ -3,6 +3,7 @@ import { resolveDefaultAgentWorkspaceDir } from "../agents/workspace.js"; import { loadConfig } from "../config/config.js"; import { createSubsystemLogger } from "../logging/subsystem.js"; import { loadOpenClawPlugins } from "./loader.js"; +import { createPluginLoaderLogger } from "./logger.js"; import type { PluginRegistry } from "./registry.js"; export type PluginStatusReport = PluginRegistry & { @@ -24,12 +25,7 @@ export function buildPluginStatusReport(params?: { const registry = loadOpenClawPlugins({ config, workspaceDir, - logger: { - info: (msg) => log.info(msg), - warn: (msg) => log.warn(msg), - error: (msg) => log.error(msg), - debug: (msg) => log.debug(msg), - }, + logger: createPluginLoaderLogger(log), }); return { diff --git a/src/plugins/tools.ts b/src/plugins/tools.ts index 7ac23105a0..155a7609ea 100644 --- a/src/plugins/tools.ts +++ b/src/plugins/tools.ts @@ -3,6 +3,7 @@ import type { AnyAgentTool } from "../agents/tools/common.js"; import { createSubsystemLogger } from "../logging/subsystem.js"; import { applyTestPluginDefaults, normalizePluginsConfig } from "./config-state.js"; import { loadOpenClawPlugins } from "./loader.js"; +import { createPluginLoaderLogger } from "./logger.js"; import type { OpenClawPluginToolContext } from "./types.js"; const log = createSubsystemLogger("plugins"); @@ -57,12 +58,7 @@ export function resolvePluginTools(params: { const registry = loadOpenClawPlugins({ config: effectiveConfig, workspaceDir: params.context.workspaceDir, - logger: { - info: (msg) => log.info(msg), - warn: (msg) => log.warn(msg), - error: (msg) => log.error(msg), - debug: (msg) => log.debug(msg), - }, + logger: createPluginLoaderLogger(log), }); const tools: AnyAgentTool[] = [];