Skip to content

Commit

Permalink
Changed the middleware name to pinoLogger (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
maou-shonen authored Oct 18, 2024
1 parent 1f8fdce commit d83fbe8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/five-hairs-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hono-pino": patch
---

Changed the middleware name to `pinoLogger`
6 changes: 4 additions & 2 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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";
10 changes: 5 additions & 5 deletions src/middleware.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -11,7 +11,7 @@ const createMockApp = (logHttpOpts?: Options["http"]) => {
const logs: Record<string, any>[] = [];
const app = new Hono()
.use(
logger({
pinoLogger({
pino: pino(
{ level: "trace", base: null, timestamp: false },
{
Expand Down Expand Up @@ -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),
);
Expand All @@ -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" &&
Expand Down
8 changes: 7 additions & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { LiteralString } from "./utils";
/**
* Pino logger middleware
*/
export const logger = <ContextKey extends string = "logger">(
export const pinoLogger = <ContextKey extends string = "logger">(
opts?: Options<LiteralString<ContextKey>>,
) => {
const rootLogger = isPino(opts?.pino) ? opts.pino : pino(opts?.pino);
Expand Down Expand Up @@ -79,5 +79,11 @@ export const logger = <ContextKey extends string = "logger">(
});
};

/**
* Pino logger middleware
* @deprecated Renamed to pinoLogger
*/
export const logger = pinoLogger;

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

0 comments on commit d83fbe8

Please sign in to comment.