nest icon indicating copy to clipboard operation
nest copied to clipboard

feat: include support for logging maps and sets

Open kuskoman opened this issue 2 years ago • 2 comments
trafficstars

PR Checklist

Please check if your PR fulfills the following requirements:

  • [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
  • [x] Tests for the changes have been added (for bug fixes / features)
  • [ ] Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • [ ] Bugfix
  • [x] Feature
  • [ ] Code style update (formatting, local variables)
  • [ ] Refactoring (no functional changes, no api changes)
  • [ ] Build related changes
  • [ ] CI related changes
  • [ ] Other... Please describe:

What is the current behavior?

[Nest] 76153  - 03/10/2023, 10:59:02 AM     LOG [RandomContext] [object Map]
[Nest] 76153  - 03/10/2023, 10:59:02 AM     LOG [RandomContext] [object Set]
[Nest] 74793  - 03/10/2023, 10:56:39 AM     LOG [RandomContext] Object:
{
         "blah": "blah",
         "map": {}
}
[Nest] 74793  - 03/10/2023, 10:56:39 AM     LOG [RandomContext] Object:
{
         "blah": "blah",
        "set": {}
}

Issue Number: #11189

What is the new behavior?

[Nest] 73354  - 03/10/2023, 10:54:11 AM     LOG [RandomContext] Map:
       {
         "foo": "bar",
         "rab": 123
      }
[Nest] 73354  - 03/10/2023, 10:54:11 AM     LOG [RandomContext] Set:
       [
         "foo",
         "bar",
         123
      ]
[Nest] 73354  - 03/10/2023, 10:54:11 AM     LOG [RandomContext] Object:
       {
         "blah": "blah",
         "set": [
           "foo",
           "bar",
           123
         ]
      }
[Nest] 73354  - 03/10/2023, 10:54:11 AM     LOG [RandomContext] Object:
       {
         "blah": "blah",
         "map": {
           "foo": "bar",
           "rab": 123
         }

Does this PR introduce a breaking change?

  • [ ] Yes
  • [ ] No

Other information

Unfortunately because the way of how JSON.stringify works making it:

"map": Map {
  "foo": "bar"
}

is pretty complex (same with set) and requires recursive parsing of objects, and excludes JSON.stringify replaces for some cases, so this RP treats Maps as objects and Sets as arrays when nested in logger.log call

kuskoman avatar Mar 10 '23 10:03 kuskoman

Pull Request Test Coverage Report for Build a9fdd683-6763-42d2-bcf8-b86b02553d72

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.885%

Totals Coverage Status
Change from base Build 691c6f82-b883-4c7f-a8c8-4e3b0232b333: 0.0%
Covered Lines: 6488
Relevant Lines: 6985

💛 - Coveralls

coveralls avatar Mar 10 '23 10:03 coveralls

@kamilmysliwiec what do you think about this PR? if you plan on adding it to one of the nestjs versions I can take some time and rebase it

kuskoman avatar Jan 17 '24 10:01 kuskoman