Skip to content

Open-source AI podcast clipper. Generate vertical clips with face tracking and burned-in captions. CLI, MCP server, web app.

server: add structured winston logger

Nika Siradzed13a5047077a
diff --git a/src/index.ts b/src/index.ts
index aefd0f4..056584e 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -9,6 +9,7 @@
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { createServer } from "./server.js";
import { FileManager } from "./services/file-manager.js";
+import { logger } from "./utils/logger.js";
async function main() {
// Ensure working directories exist
@@ -22,10 +23,10 @@ async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
- console.error("podcli MCP server running on stdio");
+ logger.info("podcli MCP server running on stdio");
}
main().catch((err) => {
- console.error("Fatal error:", err);
+ logger.error("Fatal error during startup", { err: err instanceof Error ? err.stack : err });
process.exit(1);
});
diff --git a/src/utils/logger.test.ts b/src/utils/logger.test.ts
new file mode 100644
index 0000000..36d1321
--- /dev/null
+++ b/src/utils/logger.test.ts
@@ -0,0 +1,22 @@
+import { describe, it, expect } from "vitest";
+import { logger, childLogger } from "./logger.js";
+
+describe("logger", () => {
+ it("exposes winston-compatible levels", () => {
+ expect(typeof logger.info).toBe("function");
+ expect(typeof logger.warn).toBe("function");
+ expect(typeof logger.error).toBe("function");
+ expect(typeof logger.debug).toBe("function");
+ });
+
+ it("childLogger tags messages with the module name", () => {
+ const child = childLogger("test-mod");
+ expect(child).toBeDefined();
+ expect(typeof child.info).toBe("function");
+ });
+
+ it("respects PODCLI_LOG_LEVEL default (debug in dev)", () => {
+ // level is set at import time; just verify it's a known winston level
+ expect(["silly", "debug", "verbose", "http", "info", "warn", "error"]).toContain(logger.level);
+ });
+});
diff --git a/src/utils/logger.ts b/src/utils/logger.ts
new file mode 100644
index 0000000..6f66a8f
--- /dev/null
+++ b/src/utils/logger.ts
@@ -0,0 +1,30 @@
+import winston from "winston";
+
+const level = process.env.PODCLI_LOG_LEVEL ?? (process.env.NODE_ENV === "production" ? "info" : "debug");
+
+/**
+ * Shared structured logger for the MCP server, handlers, and web UI.
+ *
+ * Writes to stderr so stdout stays clean for MCP stdio transport.
+ * Use child loggers (logger.child({ mod: "suggest-clips" })) per module.
+ */
+export const logger = winston.createLogger({
+ level,
+ format: winston.format.combine(
+ winston.format.timestamp(),
+ winston.format.errors({ stack: true }),
+ winston.format.splat(),
+ process.env.PODCLI_LOG_JSON === "1"
+ ? winston.format.json()
+ : winston.format.printf(({ timestamp, level: lvl, message, mod, ...rest }) => {
+ const tag = mod ? ` [${mod as string}]` : "";
+ const extra = Object.keys(rest).length ? ` ${JSON.stringify(rest)}` : "";
+ return `${timestamp as string} ${lvl}${tag} ${message as string}${extra}`;
+ }),
+ ),
+ transports: [new winston.transports.Console({ stderrLevels: ["error", "warn", "info", "debug"] })],
+});
+
+export function childLogger(mod: string): winston.Logger {
+ return logger.child({ mod });
+}