mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-12 09:46:03 +00:00
Log structured details when Discord persistent component registry state falls back after a store failure. - Format Error name, message, stack, and cause metadata at the Discord registry warning call site. - Forward plugin runtime logger metadata to the underlying child logger. - Add focused regression coverage for the Discord fallback warning and runtime logging adapter. - Add changelog credit for @100menotu001. Fixes #84185. Co-authored-by: OpenClaw Contributor <100menotu001@users.noreply.github.com> Co-authored-by: Craig <froelich@craigs.mac.studio.froho>
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const loggingMocks = vi.hoisted(() => {
|
|
const childLogger = {
|
|
debug: vi.fn(),
|
|
info: vi.fn(),
|
|
warn: vi.fn(),
|
|
error: vi.fn(),
|
|
};
|
|
return {
|
|
childLogger,
|
|
getChildLogger: vi.fn(() => childLogger),
|
|
};
|
|
});
|
|
|
|
vi.mock("../../globals.js", () => ({
|
|
shouldLogVerbose: vi.fn(() => false),
|
|
}));
|
|
|
|
vi.mock("../../logging.js", () => ({
|
|
getChildLogger: loggingMocks.getChildLogger,
|
|
}));
|
|
|
|
let createRuntimeLogging: typeof import("./runtime-logging.js").createRuntimeLogging;
|
|
|
|
beforeEach(async () => {
|
|
vi.clearAllMocks();
|
|
loggingMocks.getChildLogger.mockReturnValue(loggingMocks.childLogger);
|
|
({ createRuntimeLogging } = await import("./runtime-logging.js"));
|
|
});
|
|
|
|
describe("createRuntimeLogging", () => {
|
|
it("forwards structured metadata to child loggers", () => {
|
|
const logging = createRuntimeLogging();
|
|
const logger = logging.getChildLogger({ plugin: "discord" }, { level: "warn" });
|
|
const meta = {
|
|
errorName: "Error",
|
|
errorCauseName: "TypeError",
|
|
};
|
|
|
|
logger.debug?.("debug details", meta);
|
|
logger.info("info details", meta);
|
|
logger.warn("warn details", meta);
|
|
logger.error("error details", meta);
|
|
|
|
expect(loggingMocks.getChildLogger).toHaveBeenCalledWith(
|
|
{ plugin: "discord" },
|
|
{ level: "warn" },
|
|
);
|
|
expect(loggingMocks.childLogger.debug).toHaveBeenCalledWith(meta, "debug details");
|
|
expect(loggingMocks.childLogger.info).toHaveBeenCalledWith(meta, "info details");
|
|
expect(loggingMocks.childLogger.warn).toHaveBeenCalledWith(meta, "warn details");
|
|
expect(loggingMocks.childLogger.error).toHaveBeenCalledWith(meta, "error details");
|
|
});
|
|
});
|