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

fix: browser respect child logger log level #1725

Merged

Conversation

NicoVogel
Copy link
Contributor

@NicoVogel NicoVogel commented Jun 2, 2023

This PR addresses #960.

not yet completed, only a draft

Goal of this PR:

Child level determines which logs of the child are logged.

Implementation before this PR

  • the prototype of logger contains the actual log functions which should be used
  • the prototype log functions are assigned to the logger whenever the setLevel function is called
  • for log functions which level is to low, noop is assigned instead

problem: only the main logger actually changes, even if the level of a child is changed

What this PR changes

  • introduce a property which contains all the base logger functions (only the root logger has it) -> Symbol('pino.logFuncs')
    • the base log functions need to be callable independently by the child loggers and this property allows to access them all the time
  • introduce a property which contains the hierarchy of the logger (pointing to the parent) -> Symbol('pino.hierarchy')
    • whenever a child logs, it needs all bindings as they are prepend to the log arguments.
      before this PR, it was handled via the prototype chain.
  • move the responsibility of prepending the bindings into the set functions (for changing the log level)
    • as the set function is mainly responsible for defining the actual log functions that are usable, it felt like a logical step to also include the binding in it.
  • add a bindings property to each child that stores the bindings of the child.
    • this is needed to walk up the hierarchy, get all bindings and then use it to prepend the log arguments.
    • there are restrictions to this property: it is only considered once, when calling the set function.
      so, reassigning it only takes affect if the level is changed and then it only is updated for this one logger.

Insights I want to share

There is a specific order in which a log is processed:

  1. the outer log function is called with whatever should be logged
  2. the bindings are prepended to the arguments
  3. the LOG function is used to transform the arguments to the desired structure (can be found in createWrap)
  4. the actual logging function is called with the transformed arguments

Before this PR, the prototype chain was used the ensure that the bindings are prepended one after another.
Now they are collected once and then prepended at once.

Another improvement that comes with this PR as well is, that now in case of noop the logger actually does nothing.
Before this PR, it always prepended the bindings and transformed the arguments no matter if the noop function was used or not.

there is a valid case as well and that is if a transmit exists, but this is properly handled

Finally, the base log functions are now only once defined in the setupBaseLogFunctions instead of in every set call.

@NicoVogel
Copy link
Contributor Author

I am still not sure if the approach I take actually goes into the right direction.
My guess is that there should be a better way of solving this with the prototype chain, but I have a hard time getting into this mind set, because I never needed to work with prototypes before.

Anyone has a guess here?

@mcollina
Copy link
Member

mcollina commented Jun 5, 2023

Yes, I like this approach.

@NicoVogel NicoVogel force-pushed the fix/browser-child-level-independence branch from 437419c to ff199da Compare June 19, 2023 17:05
@NicoVogel NicoVogel marked this pull request as ready for review June 19, 2023 17:30
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@NicoVogel
Copy link
Contributor Author

@mcollina I noticed that I used feat in the commit message instead of fix. Should I fix this or do you use squash commits anyways?

Furthermore, I am unsure how to proceed with the failing checks.

  • the benchmark for current (master) failed, but I can't fix that in this PR
  • 14 windows failed the installation of dependencies, but I did not touch the dependencies

As for windows 16 and 18, I will try to figure out why this fails

@mcollina mcollina merged commit 32b759d into pinojs:master Jun 29, 2023
15 of 19 checks passed
@NicoVogel
Copy link
Contributor Author

@mcollina I noticed that no new release is yet available that contains the fix.
Is there still some work open?

@NicoVogel NicoVogel deleted the fix/browser-child-level-independence branch July 26, 2023 10:26
renovate bot added a commit to fwouts/previewjs that referenced this pull request Jul 27, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [pino](https://getpino.io)
([source](https://togithub.com/pinojs/pino)) | [`^8.14.1` ->
`^8.14.2`](https://renovatebot.com/diffs/npm/pino/8.14.1/8.14.2) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/pino/8.14.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/pino/8.14.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/pino/8.14.1/8.14.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/pino/8.14.1/8.14.2?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>pinojs/pino (pino)</summary>

### [`v8.14.2`](https://togithub.com/pinojs/pino/releases/tag/v8.14.2)

[Compare
Source](https://togithub.com/pinojs/pino/compare/v8.14.1...v8.14.2)

#### What's Changed

- build(deps-dev): bump
[@&#8203;types/node](https://togithub.com/types/node) from 18.16.14 to
20.2.3 by [@&#8203;dependabot](https://togithub.com/dependabot) in
[pinojs/pino#1718
- build(deps-dev): bump rimraf from 4.4.1 to 5.0.1 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[pinojs/pino#1719
- build(deps-dev): bump pino-pretty from 9.4.0 to 10.0.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[pinojs/pino#1670
- docs: add pino-slack-webhook to list of v7+ compatible transports by
[@&#8203;youngkiu](https://togithub.com/youngkiu) in
[pinojs/pino#1730
- Add missing closing curly brace in transports documentation by
[@&#8203;JasoonS](https://togithub.com/JasoonS) in
[pinojs/pino#1737
- Issue [#&#8203;1735](https://togithub.com/pinojs/pino/issues/1735) -
Programmatic Integration as a transport fails by
[@&#8203;altearius](https://togithub.com/altearius) in
[pinojs/pino#1739
- build(deps-dev): bump typescript from 4.9.5 to 5.1.3 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[pinojs/pino#1728
- build(deps-dev): bump bole from 4.0.1 to 5.0.5 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[pinojs/pino#1734
- build(deps-dev): bump eslint-plugin-n from 15.7.0 to 16.0.1 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[pinojs/pino#1740
- fix: browser respect child logger log level by
[@&#8203;NicoVogel](https://togithub.com/NicoVogel) in
[pinojs/pino#1725
- Fix dependency version by
[@&#8203;jsumners](https://togithub.com/jsumners) in
[pinojs/pino#1747
- fix: use `messageKey` when giving message precedence over error by
[@&#8203;joelmukuthu](https://togithub.com/joelmukuthu) in
[pinojs/pino#1746

#### New Contributors

- [@&#8203;youngkiu](https://togithub.com/youngkiu) made their first
contribution in
[pinojs/pino#1730
- [@&#8203;JasoonS](https://togithub.com/JasoonS) made their first
contribution in
[pinojs/pino#1737
- [@&#8203;altearius](https://togithub.com/altearius) made their first
contribution in
[pinojs/pino#1739
- [@&#8203;NicoVogel](https://togithub.com/NicoVogel) made their first
contribution in
[pinojs/pino#1725
- [@&#8203;joelmukuthu](https://togithub.com/joelmukuthu) made their
first contribution in
[pinojs/pino#1746

**Full Changelog**:
pinojs/pino@v8.14.1...v8.14.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these
updates again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/fwouts/previewjs).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4yNC4yIiwidXBkYXRlZEluVmVyIjoiMzYuMjQuMiIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot added a commit to specfy/specfy that referenced this pull request Aug 4, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [pino](https://getpino.io)
([source](https://togithub.com/pinojs/pino)) | [`8.11.0` ->
`8.15.0`](https://renovatebot.com/diffs/npm/pino/8.11.0/8.15.0) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/pino/8.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/pino/8.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/pino/8.11.0/8.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/pino/8.11.0/8.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>pinojs/pino (pino)</summary>

### [`v8.15.0`](https://togithub.com/pinojs/pino/releases/tag/v8.15.0)

[Compare
Source](https://togithub.com/pinojs/pino/compare/v8.14.2...v8.15.0)

#### What's Changed

- docs(transports): add axiom
[#&#8203;1753](https://togithub.com/pinojs/pino/issues/1753) by
[@&#8203;qlaffont](https://togithub.com/qlaffont) in
[pinojs/pino#1754
- Add pino-opentelemetry-transport as a known plugin to transports.md by
[@&#8203;Vunovati](https://togithub.com/Vunovati) in
[pinojs/pino#1757
- fix: example code in transports.md by
[@&#8203;exKAZUu](https://togithub.com/exKAZUu) in
[pinojs/pino#1761
- Add default levels to opts in multistream by
[@&#8203;tzviki](https://togithub.com/tzviki) in
[pinojs/pino#1760

#### New Contributors

- [@&#8203;qlaffont](https://togithub.com/qlaffont) made their first
contribution in
[pinojs/pino#1754
- [@&#8203;Vunovati](https://togithub.com/Vunovati) made their first
contribution in
[pinojs/pino#1757
- [@&#8203;exKAZUu](https://togithub.com/exKAZUu) made their first
contribution in
[pinojs/pino#1761
- [@&#8203;tzviki](https://togithub.com/tzviki) made their first
contribution in
[pinojs/pino#1760

**Full Changelog**:
pinojs/pino@v8.14.2...v8.15.0

### [`v8.14.2`](https://togithub.com/pinojs/pino/releases/tag/v8.14.2)

[Compare
Source](https://togithub.com/pinojs/pino/compare/v8.14.1...v8.14.2)

#### What's Changed

- build(deps-dev): bump
[@&#8203;types/node](https://togithub.com/types/node) from 18.16.14 to
20.2.3 by [@&#8203;dependabot](https://togithub.com/dependabot) in
[pinojs/pino#1718
- build(deps-dev): bump rimraf from 4.4.1 to 5.0.1 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[pinojs/pino#1719
- build(deps-dev): bump pino-pretty from 9.4.0 to 10.0.0 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[pinojs/pino#1670
- docs: add pino-slack-webhook to list of v7+ compatible transports by
[@&#8203;youngkiu](https://togithub.com/youngkiu) in
[pinojs/pino#1730
- Add missing closing curly brace in transports documentation by
[@&#8203;JasoonS](https://togithub.com/JasoonS) in
[pinojs/pino#1737
- Issue [#&#8203;1735](https://togithub.com/pinojs/pino/issues/1735) -
Programmatic Integration as a transport fails by
[@&#8203;altearius](https://togithub.com/altearius) in
[pinojs/pino#1739
- build(deps-dev): bump typescript from 4.9.5 to 5.1.3 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[pinojs/pino#1728
- build(deps-dev): bump bole from 4.0.1 to 5.0.5 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[pinojs/pino#1734
- build(deps-dev): bump eslint-plugin-n from 15.7.0 to 16.0.1 by
[@&#8203;dependabot](https://togithub.com/dependabot) in
[pinojs/pino#1740
- fix: browser respect child logger log level by
[@&#8203;NicoVogel](https://togithub.com/NicoVogel) in
[pinojs/pino#1725
- Fix dependency version by
[@&#8203;jsumners](https://togithub.com/jsumners) in
[pinojs/pino#1747
- fix: use `messageKey` when giving message precedence over error by
[@&#8203;joelmukuthu](https://togithub.com/joelmukuthu) in
[pinojs/pino#1746

#### New Contributors

- [@&#8203;youngkiu](https://togithub.com/youngkiu) made their first
contribution in
[pinojs/pino#1730
- [@&#8203;JasoonS](https://togithub.com/JasoonS) made their first
contribution in
[pinojs/pino#1737
- [@&#8203;altearius](https://togithub.com/altearius) made their first
contribution in
[pinojs/pino#1739
- [@&#8203;NicoVogel](https://togithub.com/NicoVogel) made their first
contribution in
[pinojs/pino#1725
- [@&#8203;joelmukuthu](https://togithub.com/joelmukuthu) made their
first contribution in
[pinojs/pino#1746

**Full Changelog**:
pinojs/pino@v8.14.1...v8.14.2

###
[`v8.14.1`](https://togithub.com/pinojs/pino/compare/v8.14.0...v8.14.1)

[Compare
Source](https://togithub.com/pinojs/pino/compare/v8.14.0...v8.14.1)

###
[`v8.14.0`](https://togithub.com/pinojs/pino/compare/c1c8eb41240c0ae9282bac1741ae2ee7bdb82895...v8.14.0)

[Compare
Source](https://togithub.com/pinojs/pino/compare/c1c8eb41240c0ae9282bac1741ae2ee7bdb82895...v8.14.0)

###
[`v8.12.1`](https://togithub.com/pinojs/pino/compare/v8.12.0...c1c8eb41240c0ae9282bac1741ae2ee7bdb82895)

[Compare
Source](https://togithub.com/pinojs/pino/compare/v8.12.0...c1c8eb41240c0ae9282bac1741ae2ee7bdb82895)

###
[`v8.12.0`](https://togithub.com/pinojs/pino/compare/v8.11.0...v8.12.0)

[Compare
Source](https://togithub.com/pinojs/pino/compare/v8.11.0...v8.12.0)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "after 4pm on friday,before 9am on
monday,every weekend" in timezone Europe/Paris, Automerge - At any time
(no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/specfy/specfy).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4xMS4wIiwidXBkYXRlZEluVmVyIjoiMzYuMjcuMSIsInRhcmdldEJyYW5jaCI6ImNob3JlL3Jlbm92YXRlQmFzZUJyYW5jaCJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
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.

None yet

3 participants