Skip to content

Commit

Permalink
fix: Fix incorrect structured logging by default (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
maou-shonen authored Nov 3, 2024
1 parent b383c96 commit 7c77de8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ describe("middleware", () => {
expect(logs[0]).toMatchObject(defaultResLog);
});

it("can be JSON serialize", async () => {
const { app } = createMockApp();

const res = await app.request("/");
expect(res.status).toBe(200);
expect(await res.text()).toBe("ok");
expect(logs).toHaveLength(1);
expect(() => JSON.stringify(logs[0])).not.toThrow();
});

it("with requestId middleware", async () => {
const app = new Hono()
.use(
Expand Down
4 changes: 2 additions & 2 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,5 @@ export const pinoLogger = <ContextKey extends string = "logger">(
*/
export const logger = pinoLogger;

let defaultReqId = 0n;
const defaultReqIdGenerator = () => (defaultReqId += 1n);
let defaultReqId = 0;
const defaultReqIdGenerator = () => (defaultReqId += 1);

0 comments on commit 7c77de8

Please sign in to comment.