Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(jsonlayout): maintain layout even if data in logger context #253

Open
wants to merge 2 commits into
base: production
Choose a base branch
from

Conversation

Bugslive
Copy link

Informations

Type  Status Migration
Refactor Ready No

Description

  • keep startTime, categoryName and level at the beginning of Json object when using Json Layout:
    This makes it easier to track logs

  • minor fix in CONTRIBUTING.md

Example

Before:

without additional data in logger context:
{"startTime":"2024-07-10T16:29:22.398Z","categoryName":"TSED","level":"INFO",..., "data":[]}

with additional data in logger context
const context = new LogContext(); context.set("user", "romain");
{"user": romain", "startTime":"2024-07-10T16:29:22.398Z","categoryName":"TSED","level":"INFO",..., "data":[]}

After:

with additional data in logger context
{"startTime":"2024-07-10T16:29:22.398Z","categoryName":"TSED","level":"INFO", "user": romain", ..., "data":[]}

Todos

  • [X ] Tests
  • Coverage
  • Example
  • [] Documentation

- keep startTime, categoryName and level at the beginning of Json object
- minor fix in CONTRIBUTING.md
@Bugslive
Copy link
Author

Hello @Romakita. Do you think this request could be merged ? We would appreciate to have this minor evolution.

@Romakita
Copy link
Collaborator

Hello @Bugslive
But changing the order assignment will allow data to override level, categoryName and startTime fields.

So I can't accept the change right know

startTime: loggingEvent.startTime,
categoryName: loggingEvent.categoryName,
level: loggingEvent.level.toString()
level: loggingEvent.level.toString(),
...loggingEvent.context.toJSON()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, level, startTime, categoryName can be overridden :(

- keep startTime, categoryName and level at the beginning of Json object
- startTime, categoryName and level can not be overridden
- minor fix in CONTRIBUTING.md
@Bugslive
Copy link
Author

Hello @Romakita.
I made an improvement to prevent startTime, level and categoryName to be overridden.
I also had a corresponding test.

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.

2 participants