Skip to content

fix: support nested timestampKey and messageKey paths - #678

Open
kilisamemarisaaa wants to merge 1 commit into
pinojs:masterfrom
kilisamemarisaaa:fix/nested-timestamp-message-keys
Open

fix: support nested timestampKey and messageKey paths#678
kilisamemarisaaa wants to merge 1 commit into
pinojs:masterfrom
kilisamemarisaaa:fix/nested-timestamp-message-keys

Conversation

@kilisamemarisaaa

Copy link
Copy Markdown

Summary

Fixes #438.

levelKey already supports nested / escaped property paths via getPropertyValue. timestampKey and messageKey still used top-level access (key in log / log[key]), so timestamps under Pino nestedKey (e.g. nested_key.time) were ignored and never prettified.

This PR aligns timestampKey and messageKey with the same path rules as levelKey, and removes those rendered values from the leftover object dump (including pruning empty parent objects so you do not get nested_key: {}).

Changes

  • lib/utils/prettify-time.js — resolve timestampKey with getPropertyValue; keep timestamp fallback when configured key is absent
  • lib/utils/prettify-message.js — resolve messageKey with getPropertyValue
  • lib/pretty.js — skip already-rendered message/level/time paths for nested keys when dumping the object
  • Readme.md — document nested path support for --timestampKey / --messageKey
  • Tests for nested time/message unit paths + basic factory integration

Test plan

  • node --test lib/utils/prettify-time.test.js lib/utils/prettify-message.test.js — 39/39 pass
  • node --test test/basic.test.js — 75/75 pass
  • node --test test/error-objects.test.js — 16/16 pass
  • node --test test/cli.test.js — 42/42 pass
  • node --test lib/utils/get-property-value.test.js lib/utils/prettify-level.test.js — pass
  • npx eslint on touched JS files — clean
  • Manual checks: nested time header; nested message; top-level @timestamp regression; time: 0; missing nested path does not steal root time; object dump does not repeat nested time/message

Self-review checklist (≥10)

  1. Issue Add support for dot notation when accessing custom keys #438 reproduced and scoped (nested custom keys)
  2. Confirmed no open duplicate PR for Add support for dot notation when accessing custom keys #438
  3. Matched existing levelKey / getPropertyValue conventions
  4. Minimal behavior change for top-level keys
  5. timestamp fallback preserved when configured key missing
  6. Nested miss does not incorrectly use root time
  7. time: 0 still works
  8. Object dump skips nested rendered keys + prunes empty parents
  9. Docs updated for CLI flags
  10. Unit + integration tests added
  11. Related suites green (basic/cli/error-objects)
  12. Lint clean; MIT license; no secrets

levelKey already resolved nested/escaped property paths via getPropertyValue.
timestampKey and messageKey still used top-level property access, so values
under pino nestedKey (e.g. nested_key.time) were ignored.

Use getPropertyValue for both keys, delete rendered nested paths from the
object dump (and prune empty parents), and document the same delimiter/escape
rules as levelKey.

Fixes pinojs#438

Co-Authored-By: EvoX <evox@evomap.ai>
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.

Add support for dot notation when accessing custom keys

1 participant