diff --git a/.changeset/breezy-candies-hear.md b/.changeset/breezy-candies-hear.md new file mode 100644 index 00000000..1eed7b76 --- /dev/null +++ b/.changeset/breezy-candies-hear.md @@ -0,0 +1,5 @@ +--- +'@smooai/utils': patch +--- + +Fix hono logger to have more context. diff --git a/src/api/hono.ts b/src/api/hono.ts index 4e1e5e43..3a62e6b4 100644 --- a/src/api/hono.ts +++ b/src/api/hono.ts @@ -18,14 +18,15 @@ export function addHonoMiddleware(_app: Hono): Hono { const app = _app ?? new Hono(); app.use(requestId()); - app.use( + app.use(async (c, next) => { honoLogger((str, ...rest) => { + const namespace = `[${c.req.method}] ${c.req.path}`; + logger.addRequestContext(c.req); + logger.addContext({ + namespace, + honoRequestId: c.get('requestId'), + }); logger.info(str, ...rest); - }), - ); - app.use(async (c, next) => { - logger.addContext({ - honoRequestId: c.get('requestId'), }); await next(); });