Skip to content

feat: add timestamp option to debug#16216

Open
rejunp wants to merge 2 commits intoAutomattic:masterfrom
rejunp:master
Open

feat: add timestamp option to debug#16216
rejunp wants to merge 2 commits intoAutomattic:masterfrom
rejunp:master

Conversation

@rejunp
Copy link
Copy Markdown

@rejunp rejunp commented Apr 2, 2026

Summary

This PR adds support for a timestamp option in Mongoose debug object configuration.

With this change, users can enable timestamped debug output while preserving Mongoose’s built-in formatting:

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

Example output:

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

Motivation

Mongoose debug logs are useful for understanding executed operations, but they currently lack per-line time context unless users implement a custom debug function.
This adds a built-in, low-friction option for timestamped output without requiring users to reimplement formatter logic.

What changed

  • Added debug.timestamp support in console debug output path.
  • Timestamp format is ISO 8601 and wrapped in square brackets.
  • Kept stream debug behavior unchanged.
  • Updated TypeScript option definitions to include timestamp?: boolean.
  • Added/updated tests for debug timestamp behavior.
  • Updated docs for Mongoose.prototype.set() debug option and FAQ examples.

Scope / Behavior

  • Applies to object-style debug config ({ timestamp: true }).
  • Applies to console debug output.
  • Does not add duration/performance timing.
  • Does not modify stream debug output.

Backward compatibility

  • Existing debug behavior is unchanged unless timestamp: true is explicitly set.
  • No breaking API changes.

Linked issue

Resolves #16215

Validation

  • Focused runtime debug test for timestamp output passes.
  • Type tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add timestamp option to mongoose debug object output

1 participant