[PR #4906] [CLOSED] fix: logger respects BetterAuthOptions #5649

Closed
opened 2026-03-13 12:30:26 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4906
Author: @LightTab2
Created: 9/25/2025
Status: Closed

Base: canaryHead: logger/localLogger


📝 Commits (10+)

  • 6deb6a0 fix: logger respects {BetterAuthOptions}
  • 0bb2c7e fix: allows for "success" log level
  • 7955069 fix: logging in hooks.ts
  • 31d2228 fix: missed one logging in stripe
  • 9c13b90 fix: salesforce logging
  • 03b96d9 Merge branch 'canary' into logger/localLogger
  • bd39871 Merge branch 'canary' into logger/localLogger
  • c607314 Merge remote-tracking branch 'origin/canary' into logger/localLogger
  • aff61a1 fix: telemetry
  • b2758b8 fix: import in db\utils.ts

📊 Changes

32 files changed (+345 additions, -180 deletions)

View changed files

📝 packages/better-auth/src/adapters/adapter-factory/index.ts (+15 -7)
📝 packages/better-auth/src/adapters/memory-adapter/memory-adapter.ts (+4 -2)
📝 packages/better-auth/src/api/check-endpoint-conflicts.test.ts (+6 -2)
📝 packages/better-auth/src/api/index.ts (+6 -11)
📝 packages/better-auth/src/db/utils.ts (+8 -3)
📝 packages/better-auth/src/oauth2/link-account.ts (+4 -5)
📝 packages/better-auth/src/plugins/mcp/index.ts (+6 -3)
📝 packages/better-auth/src/utils/json.ts (+2 -2)
📝 packages/cli/src/commands/generate.ts (+17 -9)
📝 packages/cli/src/commands/login.ts (+18 -8)
📝 packages/cli/src/commands/migrate.ts (+27 -11)
📝 packages/cli/src/commands/secret.ts (+7 -5)
📝 packages/cli/src/generators/auth-config.ts (+3 -3)
📝 packages/cli/src/generators/index.ts (+4 -2)
📝 packages/cli/src/utils/get-config.ts (+31 -10)
📝 packages/core/src/env/index.ts (+4 -7)
📝 packages/core/src/env/logger.test.ts (+2 -1)
📝 packages/core/src/env/logger.ts (+35 -35)
📝 packages/core/src/social-providers/atlassian.ts (+12 -3)
📝 packages/core/src/social-providers/cognito.ts (+22 -11)

...and 12 more files

📄 Description

There are some places where one needs to use a module-defined logger; however, in some of them, it's still possible to take note of the logger options from {BetterAuthOptions}.

Honestly, I have a feeling this PR might be a bad idea or is lacking something, and maybe another solution is needed. This approach forces developers to use the globalLog function instead of the module-defined variable logger. Now if you want to use a "global" logger you cannot do:

logger.warn(message, ...args);
logger.error(message, ...args);

Instead need to:

globalLog("warn", message, optionsOrNull, ...args);
globalLog("error", message, optionsOrNull, ...args);

And when you actually cannot use {BetterAuthOptions}, this null between message and ...args is unintuitive:

globalLog(level, message, null, ...args);

This PR would unclutter messages from tests though.


Summary by cubic

Make logging respect BetterAuthOptions across core and CLI. Introduces a globalLog helper and uses context loggers so log levels and disabled settings are enforced and test noise is reduced.

  • Bug Fixes

    • All logs now honor logger.disabled and logger.level from BetterAuthOptions.
    • API router and OAuth flows use the request context logger for errors and warnings.
  • Refactors

    • Added globalLog(level, message, options, ...args) and replaced direct logger.* calls in core, adapters, providers, telemetry, and CLI.
    • Standardized log messages (e.g., transaction and adapter warnings) and updated CLI commands to use globalLog while keeping messages the same.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/4906 **Author:** [@LightTab2](https://github.com/LightTab2) **Created:** 9/25/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `logger/localLogger` --- ### 📝 Commits (10+) - [`6deb6a0`](https://github.com/better-auth/better-auth/commit/6deb6a0767300319f67272ec8698debee3312a0d) fix: logger respects {`BetterAuthOptions`} - [`0bb2c7e`](https://github.com/better-auth/better-auth/commit/0bb2c7ec7e3528e9d807228e44ede138430247bc) fix: allows for "success" log level - [`7955069`](https://github.com/better-auth/better-auth/commit/79550698a3d6d32bc3fa85948dc88baa2d8f0d0d) fix: logging in `hooks.ts` - [`31d2228`](https://github.com/better-auth/better-auth/commit/31d222838ec7d317a0c0afad28616e4fdac3980c) fix: missed one logging in stripe - [`9c13b90`](https://github.com/better-auth/better-auth/commit/9c13b907fd15210618839181e67aba1b628b5de6) fix: salesforce logging - [`03b96d9`](https://github.com/better-auth/better-auth/commit/03b96d9eaf750b49a92009620122ff8b2e2650d6) Merge branch 'canary' into logger/localLogger - [`bd39871`](https://github.com/better-auth/better-auth/commit/bd39871763f209e52deb20298ef796574a9edee2) Merge branch 'canary' into logger/localLogger - [`c607314`](https://github.com/better-auth/better-auth/commit/c607314f6f5455960444a29cc6736177df123557) Merge remote-tracking branch 'origin/canary' into logger/localLogger - [`aff61a1`](https://github.com/better-auth/better-auth/commit/aff61a1e2fc6be2401efdfeb051666bf9d315d7b) fix: telemetry - [`b2758b8`](https://github.com/better-auth/better-auth/commit/b2758b8ea785eec7f6e92ea94ac1be70d75194bc) fix: import in `db\utils.ts` ### 📊 Changes **32 files changed** (+345 additions, -180 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/adapters/adapter-factory/index.ts` (+15 -7) 📝 `packages/better-auth/src/adapters/memory-adapter/memory-adapter.ts` (+4 -2) 📝 `packages/better-auth/src/api/check-endpoint-conflicts.test.ts` (+6 -2) 📝 `packages/better-auth/src/api/index.ts` (+6 -11) 📝 `packages/better-auth/src/db/utils.ts` (+8 -3) 📝 `packages/better-auth/src/oauth2/link-account.ts` (+4 -5) 📝 `packages/better-auth/src/plugins/mcp/index.ts` (+6 -3) 📝 `packages/better-auth/src/utils/json.ts` (+2 -2) 📝 `packages/cli/src/commands/generate.ts` (+17 -9) 📝 `packages/cli/src/commands/login.ts` (+18 -8) 📝 `packages/cli/src/commands/migrate.ts` (+27 -11) 📝 `packages/cli/src/commands/secret.ts` (+7 -5) 📝 `packages/cli/src/generators/auth-config.ts` (+3 -3) 📝 `packages/cli/src/generators/index.ts` (+4 -2) 📝 `packages/cli/src/utils/get-config.ts` (+31 -10) 📝 `packages/core/src/env/index.ts` (+4 -7) 📝 `packages/core/src/env/logger.test.ts` (+2 -1) 📝 `packages/core/src/env/logger.ts` (+35 -35) 📝 `packages/core/src/social-providers/atlassian.ts` (+12 -3) 📝 `packages/core/src/social-providers/cognito.ts` (+22 -11) _...and 12 more files_ </details> ### 📄 Description There are some places where one needs to use a **module-defined logger**; however, in some of them, it's still possible to take note of the `logger` options from {`BetterAuthOptions`}. Honestly, I have a feeling this PR might be a bad idea or is lacking something, and maybe another solution is needed. This approach forces developers to use the `globalLog` function instead of the module-defined variable `logger`. Now if you want to use a "global" logger you cannot do: ```js logger.warn(message, ...args); logger.error(message, ...args); ``` Instead need to: ```js globalLog("warn", message, optionsOrNull, ...args); globalLog("error", message, optionsOrNull, ...args); ``` And when you actually cannot use `{BetterAuthOptions}`, this `null` between `message` and `...args` is unintuitive: ```js globalLog(level, message, null, ...args); ``` This PR would unclutter messages from tests though. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Make logging respect BetterAuthOptions across core and CLI. Introduces a globalLog helper and uses context loggers so log levels and disabled settings are enforced and test noise is reduced. - **Bug Fixes** - All logs now honor logger.disabled and logger.level from BetterAuthOptions. - API router and OAuth flows use the request context logger for errors and warnings. - **Refactors** - Added globalLog(level, message, options, ...args) and replaced direct logger.* calls in core, adapters, providers, telemetry, and CLI. - Standardized log messages (e.g., transaction and adapter warnings) and updated CLI commands to use globalLog while keeping messages the same. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-03-13 12:30:26 -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#5649