[GH-ISSUE #1115] Pass unformatted message to custom logger.log method #17233

Closed
opened 2026-04-15 15:15:52 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @Shunseii on GitHub (Jan 3, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1115

Is this suited for github?

  • Yes, this is suited for github

I'm using pino for logging in my application and was trying to also set it up with better auth with the logger.log config option. This exposes a message argument but the issue is that the message is formatted with color and timestamp, but both of these are redundant when working with pino (or probably most other loggers). For example, with this setup:

import { logger } from "./logger"; // Pino logger

export const auth = betterAuth({
  // ...
  hooks: {
    before: createAuthMiddleware(async (ctx) => {
      ctx.context.logger.info("TESTING");
    }),
  },
  logger: {
    disabled: false,
    level: "debug",
    log: (level, message, ...args) => {
      logger[level]({ ...args }, message);
    },
  },
  // ...
})

I see this:

INFO [2025-01-03 17:23:43.867 +0000]: 2025-01-03T17:23:43.867Z INFO [Better Auth]: TESTING

whereas I expect this:

INFO [2025-01-03 17:23:43.867 +0000]: TESTING

Describe the solution you'd like

Passing through the unformatted message so that it works nicely with standard loggers.

Describe alternatives you've considered

I could potentially do a string split on [Better Auth]: but that's really not ideal since my logging could break if the better auth log format changes.

Additional context

This seems like a pretty simple change here. My thought would be to either replace formattedMessage with just the message or add a new argument for the raw message, something like that.

Happy to make a ticket for this if the general approach seems fine.

Originally created by @Shunseii on GitHub (Jan 3, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1115 ### Is this suited for github? - [X] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. I'm using pino for logging in my application and was trying to also set it up with better auth with the `logger.log` config option. This exposes a `message` argument but the issue is that the message is formatted with color and timestamp, but both of these are redundant when working with pino (or probably most other loggers). For example, with this setup: ```typescript import { logger } from "./logger"; // Pino logger export const auth = betterAuth({ // ... hooks: { before: createAuthMiddleware(async (ctx) => { ctx.context.logger.info("TESTING"); }), }, logger: { disabled: false, level: "debug", log: (level, message, ...args) => { logger[level]({ ...args }, message); }, }, // ... }) ``` I see this: ``` INFO [2025-01-03 17:23:43.867 +0000]: 2025-01-03T17:23:43.867Z INFO [Better Auth]: TESTING ``` whereas I expect this: ``` INFO [2025-01-03 17:23:43.867 +0000]: TESTING ``` ### Describe the solution you'd like Passing through the unformatted message so that it works nicely with standard loggers. ### Describe alternatives you've considered I could potentially do a string split on `[Better Auth]:` but that's really not ideal since my logging could break if the better auth log format changes. ### Additional context This seems like a pretty simple change [here](https://github.com/better-auth/better-auth/blob/main/packages/better-auth/src/utils/logger.ts#L104-L109). My thought would be to either replace `formattedMessage` with just the `message` or add a new argument for the raw message, something like that. Happy to make a ticket for this if the general approach seems fine.
GiteaMirror added the locked label 2026-04-15 15:15:52 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17233