diff --git a/.changeset/five-hairs-reply.md b/.changeset/five-hairs-reply.md new file mode 100644 index 0000000..9a1d41e --- /dev/null +++ b/.changeset/five-hairs-reply.md @@ -0,0 +1,5 @@ +--- +"hono-pino": patch +--- + +Changed the middleware name to `pinoLogger` diff --git a/src/index.test.ts b/src/index.test.ts index d5fb643..8bad850 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -6,6 +6,8 @@ it("should have exports", () => { }); it("should not have undefined exports", () => { - for (const k of Object.keys(myPackage)) - expect(myPackage).not.toHaveProperty(k, undefined); + expect(myPackage).toHaveProperty("logger"); + expect(myPackage).toHaveProperty("pinoLogger"); + expect(myPackage).toHaveProperty("PinoLogger"); + expect(myPackage).toHaveProperty("getLogger"); }); diff --git a/src/index.ts b/src/index.ts index 14b4838..b86d6c3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export { logger } from "./middleware"; +export { pinoLogger, logger } from "./middleware"; export { PinoLogger } from "./logger"; export { getLogger } from "./utils"; export type { Options, Env } from "./types"; diff --git a/src/middleware.test.ts b/src/middleware.test.ts index def7b40..09a6326 100644 --- a/src/middleware.test.ts +++ b/src/middleware.test.ts @@ -1,6 +1,6 @@ import { describe, it, expect } from "vitest"; import { Hono } from "hono"; -import { logger } from "./middleware"; +import { pinoLogger } from "./middleware"; import type { Options } from "./types"; import { pino } from "pino"; import { PinoLogger } from "./logger"; @@ -11,7 +11,7 @@ const createMockApp = (logHttpOpts?: Options["http"]) => { const logs: Record[] = []; const app = new Hono() .use( - logger({ + pinoLogger({ pino: pino( { level: "trace", base: null, timestamp: false }, { @@ -228,7 +228,7 @@ describe("contextKey option", () => { it("basic", async () => { const app = new Hono() - .use(logger()) + .use(pinoLogger()) .get("/", async (c) => c.text(c.get("logger") instanceof PinoLogger ? "ok" : "fail", 200), ); @@ -240,8 +240,8 @@ describe("contextKey option", () => { it("multiple logger", async () => { const app = new Hono() - .use(logger({ contextKey: "logger1" as const, pino: pino1 })) - .use(logger({ contextKey: "logger2" as const, pino: pino2 })) + .use(pinoLogger({ contextKey: "logger1" as const, pino: pino1 })) + .use(pinoLogger({ contextKey: "logger2" as const, pino: pino2 })) .get("/", async (c) => c.text( c.get("logger1").logger.bindings().name === "pino1" && diff --git a/src/middleware.ts b/src/middleware.ts index d845868..b9b9527 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -9,7 +9,7 @@ import type { LiteralString } from "./utils"; /** * Pino logger middleware */ -export const logger = ( +export const pinoLogger = ( opts?: Options>, ) => { const rootLogger = isPino(opts?.pino) ? opts.pino : pino(opts?.pino); @@ -79,5 +79,11 @@ export const logger = ( }); }; +/** + * Pino logger middleware + * @deprecated Renamed to pinoLogger + */ +export const logger = pinoLogger; + let defaultReqId = 0n; const defaultReqIdGenerator = () => (defaultReqId += 1n);