Skip to content

Commit df71a28

Browse files
authored
Fix hono logger to have more context. (#102)
* Updated dependency. * Enhance Hono logger with additional context and fix to include request method and path for better traceability
1 parent 46c4faf commit df71a28

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

.changeset/breezy-candies-hear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@smooai/utils': patch
3+
---
4+
5+
Fix hono logger to have more context.

src/api/hono.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ export function addHonoMiddleware(_app: Hono<any>): Hono<any> {
1818
const app = _app ?? new Hono();
1919

2020
app.use(requestId());
21-
app.use(
21+
app.use(async (c, next) => {
2222
honoLogger((str, ...rest) => {
23+
const namespace = `[${c.req.method}] ${c.req.path}`;
24+
logger.addRequestContext(c.req);
25+
logger.addContext({
26+
namespace,
27+
honoRequestId: c.get('requestId'),
28+
});
2329
logger.info(str, ...rest);
24-
}),
25-
);
26-
app.use(async (c, next) => {
27-
logger.addContext({
28-
honoRequestId: c.get('requestId'),
2930
});
3031
await next();
3132
});

0 commit comments

Comments
 (0)