[GH-ISSUE #6408] Logger doesn't log error level logs when set to info #27830

Closed
opened 2026-04-17 19:03:33 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @danielfinke on GitHub (Nov 29, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6408

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Configure logger with log level 'info'
  2. Log something with context.logger.error (e.g. noticed when encountering an OAuth2 state mismatch)

Current vs. Expected behavior

Current behavior

The log is not written.

Expected behavior

The log is written. 'error' is of higher severity than 'info', therefore it should be written.

The level priority is set here. It seems like this should be ["debug", "info", "success", "warn", "error"] and the check of shouldPublishLog should be reversed. This would ensure that logs with severity equal or greater than the configured level would be logged.

I didn't want to just make the PR for this because I wasn't sure if there was some expectation I was missing, but this seemed incorrect with respect to logging in any other codebase.

What version of Better Auth are you using?

1.4.3

System info

📊 Better Auth System Information

==================================================

🖥️  System Information:
  platform: darwin
  arch: arm64
  version: Darwin Kernel Version 24.6.0: Mon Aug 11 21:16:21 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6000
  release: 24.6.0
  cpuCount: 10
  cpuModel: Apple M1 Max
  totalMemory: 64.00 GB
  freeMemory: 0.21 GB

📦 Node.js:
  version: v20.18.1
  env: development

📦 Package Manager:
  name: pnpm
  version: 10.2.1

🔐 Better Auth:
  Version: ^1.4.3
  Configuration:
    appName: <appname>
    advanced:
      cookiePrefix: <cookiePrefix>
      useSecureCookies: true
    basePath: /auth
    hooks:
      {}
    logger:
      level: info
    plugins: name: jwt
config:
  id: jwt
  options:
    jwt:
      issuer: <issuer>
      audience: <audience>
      expirationTime: 1d
    schema:
      jwks:
        modelName: JWKS
  endpoints:
    {}
  hooks:
    after: {}
  schema:
    jwks:
      fields:
        publicKey:
          type: string
          required: true
        privateKey:
          type: string
          required: true
        createdAt:
          type: date
          required: true
        expiresAt:
          type: date
          required: false
      modelName: JWKS
name: expo
config:
  id: expo
  hooks:
    after: {}
  endpoints:
    {}
name: custom-session
config:
  id: custom-session
name: email-otp
config:
  id: email-otp
  endpoints:
    {}
  hooks:
    after: {}
  $ERROR_CODES:
    OTP_EXPIRED: OTP expired
    INVALID_OTP: Invalid OTP
    TOO_MANY_ATTEMPTS: Too many attempts
  rateLimit: window: 60
max: 3
window: 60
max: 3
window: 60
max: 3
window: 60
max: 3
name: signInSocial
config:
  id: signInSocial
  endpoints:
    {}
name: open-api
config:
  id: open-api
  endpoints:
    {}
    telemetry:
      enabled: false
    trustedOrigins: https://appleid.apple.com
    user:
      modelName: AccountUser
    account:
      modelName: AccountCredential
      accountLinking:
        updateUserInfoOnLink: true
      encryptOAuthTokens: true
    session:
      modelName: AccountSession
      cookieCache:
        enabled: true
      expiresIn: 2592000
      additionalFields:
        providerId:
          type: string
          input: false
          references:
            model: AccountCredential
            field: providerId
          required: false
          returned: true
        accountId:
          type: string
          input: false
          references:
            model: Account
            field: _id
          required: false
          returned: true
    verification:
      modelName: AccountVerification
    socialProviders:
      {}

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)

import { betterAuth } from 'better-auth';

export const auth = betterAuth({
  appName: '<appname>',
  advanced: {
    cookiePrefix: '<cookiePrefix>',
    useSecureCookies: process.env.NODE_ENV !== 'development',
  },
  baseURL: config.baseURL,
  basePath: '/auth',
  logger: {
    level: 'info',
  },
  // plugins,
  secret: config.secret,
  telemetry: { enabled: false },
  trustedOrigins: [
    ...config.trustedOrigins,
    // Required for Sign In with Apple flows
    'https://appleid.apple.com',
  ],

  // Core schema
  user: {
    modelName: 'AccountUser',
  },
  account: {
    modelName: 'AccountCredential',
    accountLinking: {
      updateUserInfoOnLink: true,
    },
    encryptOAuthTokens: true,
  },
  session: {
    modelName: 'AccountSession',
    cookieCache: {
      enabled: true,
    },
    expiresIn: 60 * 60 * 24 * 30, // 30 days
    additionalFields: {
      providerId: {
        type: 'string',
        input: false,
        references: {
          model: 'AccountCredential',
          field: 'providerId',
        },
        required: false,
        returned: true,
      },
      accountId: {
        type: 'string',
        input: false,
        references: {
          model: 'Account',
          field: '_id',
        },
        required: false,
        returned: true,
      },
    },
  },
  verification: {
    modelName: 'AccountVerification',
  },

  // Core authentication mechanisms
  // socialProviders: configureSocialProviders(config),
});

Additional context

No response

Originally created by @danielfinke on GitHub (Nov 29, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6408 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Configure logger with log level `'info'` 2. Log something with `context.logger.error` (e.g. noticed when encountering an OAuth2 state mismatch) ### Current vs. Expected behavior #### Current behavior The log is not written. #### Expected behavior The log _is_ written. `'error'` is of higher severity than `'info'`, therefore it should be written. The level priority is set [here](https://github.com/better-auth/better-auth/blob/b6d405f75a70b4795b85e81d8fee1f922ed58c4d/packages/core/src/env/logger.ts#L36). It seems like this should be `["debug", "info", "success", "warn", "error"]` and the check of [shouldPublishLog](https://github.com/better-auth/better-auth/blob/b6d405f75a70b4795b85e81d8fee1f922ed58c4d/packages/core/src/env/logger.ts#L42) should be reversed. This would ensure that logs with severity equal or greater than the configured level would be logged. I didn't want to just make the PR for this because I wasn't sure if there was some expectation I was missing, but this seemed incorrect with respect to logging in any other codebase. ### What version of Better Auth are you using? 1.4.3 ### System info ```bash 📊 Better Auth System Information ================================================== 🖥️ System Information: platform: darwin arch: arm64 version: Darwin Kernel Version 24.6.0: Mon Aug 11 21:16:21 PDT 2025; root:xnu-11417.140.69.701.11~1/RELEASE_ARM64_T6000 release: 24.6.0 cpuCount: 10 cpuModel: Apple M1 Max totalMemory: 64.00 GB freeMemory: 0.21 GB 📦 Node.js: version: v20.18.1 env: development 📦 Package Manager: name: pnpm version: 10.2.1 🔐 Better Auth: Version: ^1.4.3 Configuration: appName: <appname> advanced: cookiePrefix: <cookiePrefix> useSecureCookies: true basePath: /auth hooks: {} logger: level: info plugins: name: jwt config: id: jwt options: jwt: issuer: <issuer> audience: <audience> expirationTime: 1d schema: jwks: modelName: JWKS endpoints: {} hooks: after: {} schema: jwks: fields: publicKey: type: string required: true privateKey: type: string required: true createdAt: type: date required: true expiresAt: type: date required: false modelName: JWKS name: expo config: id: expo hooks: after: {} endpoints: {} name: custom-session config: id: custom-session name: email-otp config: id: email-otp endpoints: {} hooks: after: {} $ERROR_CODES: OTP_EXPIRED: OTP expired INVALID_OTP: Invalid OTP TOO_MANY_ATTEMPTS: Too many attempts rateLimit: window: 60 max: 3 window: 60 max: 3 window: 60 max: 3 window: 60 max: 3 name: signInSocial config: id: signInSocial endpoints: {} name: open-api config: id: open-api endpoints: {} telemetry: enabled: false trustedOrigins: https://appleid.apple.com user: modelName: AccountUser account: modelName: AccountCredential accountLinking: updateUserInfoOnLink: true encryptOAuthTokens: true session: modelName: AccountSession cookieCache: enabled: true expiresIn: 2592000 additionalFields: providerId: type: string input: false references: model: AccountCredential field: providerId required: false returned: true accountId: type: string input: false references: model: Account field: _id required: false returned: true verification: modelName: AccountVerification socialProviders: {} ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from 'better-auth'; export const auth = betterAuth({ appName: '<appname>', advanced: { cookiePrefix: '<cookiePrefix>', useSecureCookies: process.env.NODE_ENV !== 'development', }, baseURL: config.baseURL, basePath: '/auth', logger: { level: 'info', }, // plugins, secret: config.secret, telemetry: { enabled: false }, trustedOrigins: [ ...config.trustedOrigins, // Required for Sign In with Apple flows 'https://appleid.apple.com', ], // Core schema user: { modelName: 'AccountUser', }, account: { modelName: 'AccountCredential', accountLinking: { updateUserInfoOnLink: true, }, encryptOAuthTokens: true, }, session: { modelName: 'AccountSession', cookieCache: { enabled: true, }, expiresIn: 60 * 60 * 24 * 30, // 30 days additionalFields: { providerId: { type: 'string', input: false, references: { model: 'AccountCredential', field: 'providerId', }, required: false, returned: true, }, accountId: { type: 'string', input: false, references: { model: 'Account', field: '_id', }, required: false, returned: true, }, }, }, verification: { modelName: 'AccountVerification', }, // Core authentication mechanisms // socialProviders: configureSocialProviders(config), }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-17 19:03:33 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 29, 2025):

Hi there, thanks for reporting this! The issue appears to be that the logger’s severity comparison is inverted – the ordering of levels (debug, info, success, warn, error) means that error messages should indeed be visible when the level is set to info. In our code, the check in the log publishing helper is reversed, which prevents error-level logs from being written when the configured level is info [1].

Could you try temporarily setting the logger level to “error” to verify that error logs then appear? Also, please let us know if you have any further observations or if you’d like a patch for this behavior. Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3591836285 --> @better-auth-agent[bot] commented on GitHub (Nov 29, 2025): Hi there, thanks for reporting this! The issue appears to be that the logger’s severity comparison is inverted – the ordering of levels (debug, info, success, warn, error) means that error messages should indeed be visible when the level is set to info. In our code, the check in the log publishing helper is reversed, which prevents error-level logs from being written when the configured level is info [[1]](https://github.com/better-auth/better-auth/issues/4125). Could you try temporarily setting the logger level to “error” to verify that error logs then appear? Also, please let us know if you have any further observations or if you’d like a patch for this behavior. Tag @better-auth-agent if you would like an answer from the Agent. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@danielfinke commented on GitHub (Nov 29, 2025):

Could you try temporarily setting the logger level to “error” to verify that error logs then appear?

Confirmed - the logs are written when setting the level to 'error'.

<!-- gh-comment-id:3591845721 --> @danielfinke commented on GitHub (Nov 29, 2025): > Could you try temporarily setting the logger level to “error” to verify that error logs then appear? Confirmed - the logs are written when setting the level to `'error'`.
Author
Owner

@rovertrack commented on GitHub (Nov 29, 2025):

Could you try temporarily setting the logger level to “error” to verify that error logs then appear?

Confirmed - the logs are written when setting the level to 'error'.

@better-auth-agent

<!-- gh-comment-id:3591862695 --> @rovertrack commented on GitHub (Nov 29, 2025): > > Could you try temporarily setting the logger level to “error” to verify that error logs then appear? > > Confirmed - the logs are written when setting the level to `'error'`. @better-auth-agent
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 29, 2025):

It looks like the issue is due to the current logger's filtering logic where the severity ordering might be reversed. The fact that setting the logger level to “error” makes the error logs appear confirms that error-level logs are not being published when the level is set to “info” (which should include higher-severity logs like error) [1].

To troubleshoot further, you can try:
• Temporarily using a custom logger adapter or directly modifying the check in the logger’s shouldPublishLog function to see if reversing the condition maintains the expected behavior.
• Reviewing the logger configuration to ensure no other settings or middleware are overriding the logging behavior [1].
• If you confirm that reversing the severity check in the code (i.e., adjusting the order to ["debug", "info", "success", "warn", "error"] and altering the comparison logic) resolves the issue, you might consider opening a pull request or filing a detailed issue with the maintainers.

Have you tried any temporary workarounds or further diagnostics on your end? Tag @better-auth-agent if you would like an answer from the Agent.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3591862851 --> @better-auth-agent[bot] commented on GitHub (Nov 29, 2025): It looks like the issue is due to the current logger's filtering logic where the severity ordering might be reversed. The fact that setting the logger level to “error” makes the error logs appear confirms that error-level logs are not being published when the level is set to “info” (which should include higher-severity logs like error) [[1]](https://github.com/better-auth/better-auth/issues/4125). To troubleshoot further, you can try: • Temporarily using a custom logger adapter or directly modifying the check in the logger’s shouldPublishLog function to see if reversing the condition maintains the expected behavior. • Reviewing the logger configuration to ensure no other settings or middleware are overriding the logging behavior [[1]](https://github.com/better-auth/better-auth/issues/4125). • If you confirm that reversing the severity check in the code (i.e., adjusting the order to ["debug", "info", "success", "warn", "error"] and altering the comparison logic) resolves the issue, you might consider opening a pull request or filing a detailed issue with the maintainers. Have you tried any temporary workarounds or further diagnostics on your end? Tag @better-auth-agent if you would like an answer from the Agent. <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27830