Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
feat(logging): color http methods in dev access line
Sidwebworks50237bd8ea47
diff --git a/packages/logger/src/http-formatter.test.ts b/packages/logger/src/http-formatter.test.tsindex de751809af..5aef7edffe 100644--- a/packages/logger/src/http-formatter.test.ts+++ b/packages/logger/src/http-formatter.test.ts@@ -39,7 +39,7 @@ describe("httpDevFormatter", () => {expect(line).toContain("/callback?ref=home&token=%5BREDACTED%5D");});- it("renders the message portion as a morgan dev-style access line — bold method, dimmed duration", () => {+ it("renders the message portion as a morgan dev-style access line — bold colored method, dimmed duration", () => {const line = httpDevFormatter(record({method: "GET",@@ -49,10 +49,24 @@ describe("httpDevFormatter", () => {}));expect(line).toContain(- "\x1b[1mGET\x1b[0m /dashboard \x1b[32m200\x1b[0m \x1b[2m12.3 ms\x1b[0m"+ "\x1b[1m\x1b[32mGET\x1b[0m /dashboard \x1b[32m200\x1b[0m \x1b[2m12.3 ms\x1b[0m");});+ it("colors the method: GET green, POST yellow, DELETE red", () => {+ expect(+ httpDevFormatter(record({ method: "GET", pathname: "/x", status: 200 }))+ ).toContain("\x1b[1m\x1b[32mGET\x1b[0m");+ expect(+ httpDevFormatter(record({ method: "POST", pathname: "/x", status: 200 }))+ ).toContain("\x1b[1m\x1b[33mPOST\x1b[0m");+ expect(+ httpDevFormatter(+ record({ method: "DELETE", pathname: "/x", status: 200 })+ )+ ).toContain("\x1b[1m\x1b[31mDELETE\x1b[0m");+ });+it("colors 3xx cyan, 4xx yellow, 5xx red", () => {expect(httpDevFormatter(record({ method: "GET", pathname: "/x", status: 301 }))@@ -89,7 +103,7 @@ describe("httpDevFormatter", () => {const line = httpDevFormatter(record({ method: "GET", pathname: "/x", status: 200 }));- expect(line).toContain("\x1b[1mGET\x1b[0m /x \x1b[32m200\x1b[0m");+ expect(line).toContain("\x1b[1m\x1b[32mGET\x1b[0m /x \x1b[32m200\x1b[0m");expect(line).not.toContain("ms");});diff --git a/packages/logger/src/http-formatter.ts b/packages/logger/src/http-formatter.tsindex a92c1038e6..349ef9186f 100644--- a/packages/logger/src/http-formatter.ts+++ b/packages/logger/src/http-formatter.ts@@ -23,6 +23,17 @@ const LEVEL_COLOR: Record<string, string> = {fatal: "\x1b[35m"};+/** Per-method color: read green, create yellow, replace blue, patch cyan, delete red. */+const METHOD_COLOR: Record<string, string> = {+ GET: "\x1b[32m",+ HEAD: "\x1b[32m",+ POST: "\x1b[33m",+ PUT: "\x1b[34m",+ PATCH: "\x1b[36m",+ DELETE: "\x1b[31m",+ OPTIONS: "\x1b[35m"+};+/** Time-only `HH:MM:SS.mmm` from an epoch-ms timestamp (no date). */function clockTime(ts: number): string {const d = new Date(ts);@@ -60,7 +71,8 @@ export const httpDevFormatter: TextFormatter = getAnsiColorFormatter({typeof responseTime === "number"? ` ${DIM}${Math.trunc(responseTime * 10) / 10} ms${RESET}`: "";- line = `${BOLD}${method}${RESET} ${pathname}${query} ${statusColor(status)}${status}${RESET}${time}`;+ const methodColor = METHOD_COLOR[method] ?? RESET;+ line = `${BOLD}${methodColor}${method}${RESET} ${pathname}${query} ${statusColor(status)}${status}${RESET}${time}`;// The Morgan line only renders method/path/status/time, so a captured// request body (debug only, already redacted) would otherwise be dropped// — append it dimmed on its own line.