Skip to content

Add an option to avoid pulling object properties to the top level #57

@mfursov

Description

@mfursov

Today console-log-json pulls object properties passed as args to the top level.
Example:

 console.log('Hello', {a: 1}, {a: 2}, {a: 3}, 'World', {a: 4});

results to

{"level":"info","message":"Hello - World","___a":4,"__a":3,"_a":2,"a":1,"@timestamp":"2023-06-28T22:40:29.491Z"}

The behavior I suggest:

  1. Add a configuration option: CONSOLE_LOG_TOP_LEVEL_PROPERTIES_FIELD = 'topLevelPropsFieldName'
  2. When this option is set for the input above produce the following output:
{"level":"info","message":"Hello [0], [1], [2] World [3]",  "[0]":{"a":1},  "[1]":{"a":2}, "[2]":{"a":3},  "[3]":{"a":4},  "@timestamp":"2023-06-28T22:40:29.491Z"}

and use only properties from the {"topLevelPropsFieldName": {...}} to populate the top level.

Why this is needed:
Without this manual and explicit control 'random' properties go to the top level and this may affect other tools (like DataDog filters)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions