From 12d94acb53c23f9b1df68ff44acc012efdb39d97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=94=E7=8E=8B=E5=B0=91=E5=B9=B4?= Date: Sun, 20 Oct 2024 14:38:17 +0800 Subject: [PATCH 1/2] Change internal `logger` to `_logger` --- src/logger.ts | 23 ++++++++++++----------- src/middleware.test.ts | 4 ++-- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/logger.ts b/src/logger.ts index b141843..957fef7 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -2,7 +2,7 @@ import { pino } from "pino"; export interface PinoLogger { - logger: pino.Logger; + _logger: pino.Logger; trace: pino.LogFn; debug: pino.LogFn; info: pino.LogFn; @@ -13,19 +13,20 @@ export interface PinoLogger { export class PinoLogger { #rootLogger: pino.Logger; - logger: pino.Logger; + // Use the _ prefix to indicate that this should not be used + _logger: pino.Logger; constructor(rootLogger: pino.Logger) { this.#rootLogger = rootLogger.child({}); - this.logger = rootLogger; + this._logger = rootLogger; } /** * assign bindings to http log context */ assign(bindings: pino.Bindings) { - this.logger = this.#rootLogger.child({ - ...this.logger.bindings(), + this._logger = this.#rootLogger.child({ + ...this._logger.bindings(), ...bindings, }); } @@ -34,35 +35,35 @@ export class PinoLogger { // eslint-disable-next-line @typescript-eslint/no-explicit-any PinoLogger.prototype.trace = function (this, ...args: [any, ...any]) { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - this.logger.trace(...args); + this._logger.trace(...args); }; // eslint-disable-next-line @typescript-eslint/no-explicit-any PinoLogger.prototype.debug = function (this, ...args: [any, ...any[]]) { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - this.logger.debug(...args); + this._logger.debug(...args); }; // eslint-disable-next-line @typescript-eslint/no-explicit-any PinoLogger.prototype.info = function (this, ...args: [any, ...any]) { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - this.logger.info(...args); + this._logger.info(...args); }; // eslint-disable-next-line @typescript-eslint/no-explicit-any PinoLogger.prototype.warn = function (this, ...args: [any, ...any]) { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - this.logger.warn(...args); + this._logger.warn(...args); }; // eslint-disable-next-line @typescript-eslint/no-explicit-any PinoLogger.prototype.error = function (this, ...args: [any, ...any]) { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - this.logger.error(...args); + this._logger.error(...args); }; // eslint-disable-next-line @typescript-eslint/no-explicit-any PinoLogger.prototype.fatal = function (this, ...args: [any, ...any]) { // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - this.logger.fatal(...args); + this._logger.fatal(...args); }; diff --git a/src/middleware.test.ts b/src/middleware.test.ts index 09a6326..87f8b73 100644 --- a/src/middleware.test.ts +++ b/src/middleware.test.ts @@ -244,8 +244,8 @@ describe("contextKey option", () => { .use(pinoLogger({ contextKey: "logger2" as const, pino: pino2 })) .get("/", async (c) => c.text( - c.get("logger1").logger.bindings().name === "pino1" && - c.get("logger2").logger.bindings().name === "pino2" + c.get("logger1")._logger.bindings().name === "pino1" && + c.get("logger2")._logger.bindings().name === "pino2" ? "ok" : "fail", 200, From d29ea81f74f5b6814020d964ec3b566618e5de06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=94=E7=8E=8B=E5=B0=91=E5=B9=B4?= Date: Sun, 20 Oct 2024 14:39:42 +0800 Subject: [PATCH 2/2] add changeset --- .changeset/quick-lobsters-accept.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/quick-lobsters-accept.md diff --git a/.changeset/quick-lobsters-accept.md b/.changeset/quick-lobsters-accept.md new file mode 100644 index 0000000..c61ddeb --- /dev/null +++ b/.changeset/quick-lobsters-accept.md @@ -0,0 +1,5 @@ +--- +"hono-pino": patch +--- + +Change internal `logger` to `_logger`