Skip to content

feat: add timestamp option to mongoose debug object output #16215

@rejunp

Description

@rejunp

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the feature has not already been requested

🚀 Feature Proposal

Summary

I’d like to propose adding a timestamp option to Mongoose’s debug object config, similar to existing color and shell options.

Motivation

Today, if users want timestamped debug output, they need to pass a custom debug function and reimplement Mongoose’s built-in formatting behavior.
A built-in option would let users keep the existing Mongoose debug formatting while adding a clear timestamp prefix.

Proposed API

mongoose.set('debug', { timestamp: true });

This would prefix console debug output with an ISO timestamp (in brackets), for example:

[2026-04-02T10:00:00.000Z] Mongoose: users.findOne({}, {})

Scope

  • Apply timestamp to standard console debug output ($print path).
  • Keep existing behavior for stream debug output (stream.Writable) unchanged.
  • timestamp is formatting-only; it does not report query execution duration.

Why this helps

  • Improves log readability and event correlation.
  • Preserves Mongoose’s built-in debug formatting.
  • Avoids requiring users to write and maintain custom debug logger functions.

Notes

If this proposal is acceptable, I can open a PR with implementation and tests.

Motivation

Debug logs are often used to correlate application behavior with external events and incident timelines. While Mongoose debug output already shows operation details, it does not include when each operation was logged. That makes timeline analysis harder during production troubleshooting.

Users can work around this by supplying a custom debug function, but that requires reimplementing Mongoose’s built-in formatting. In practice, this is repetitive, error-prone, and leads to inconsistent log output across codebases.

Adding a timestamp option to the existing debug object configuration solves this with minimal API surface:

  • preserves Mongoose’s default debug formatting
  • adds clear per-line time context ([ISO_TIMESTAMP])
  • improves observability without custom logger code
  • follows the existing debug option style (color, shell)

In short, this proposal improves debugging ergonomics and log correlation while preserving backward compatibility and current defaults.

Example

[2026-04-02T10:00:03.456Z] Mongoose: products.aggregate([ { '$match': { active: true } } ], {})
[2026-04-02T10:00:05.345Z] Mongoose: events.find({ createdAt: { '$gte': ISODate("Thu, 02 Apr 2026 10:00:00 GMT") }}, {})

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis issue is a user-facing general improvement that doesn't fix a bug or add a new featurenew featureThis change adds new functionality, like a new method or class

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions