Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Remove use of logging methods in conditional tests #677

Merged
merged 2 commits into from
Nov 13, 2020

Conversation

terziani
Copy link
Contributor

To address issue #676 .

Use of log methods (e.g. log.trace()) in conditional tests prior to actually logging messages yields undesirable behavior when using Pino as an alternative to Bunyan (and potentially other Bunyan-like packages).

  1. Pino methods have void return values and always fail the conditional test
  2. Pino method calls with no parameters still produce a logging event with several default values but no message field

Additionally, the default behavior for Bunyan and similar loggers is to filter events based on instance config options. The conditionals are not necessary.

if (log.trace) { log.trace('data event: %s', util.inspect(data)) }
log.trace('data event: %s', util.inspect(data))
Copy link
Member

@UziTech UziTech Nov 12, 2020

Choose a reason for hiding this comment

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

Was the if statement supposed to check for the existence of the function? If the user does not provide a logger (or a logger that does not provide a trace method) does this throw an error?

It looks like some of the if statements check the return value and some check the function (like this one did).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good points. Integration with logging packages isn't terribly strict, though it is functional. The risk is pushed onto the developer that wants to make use of the built-in calls.

Was the if statement supposed to check for the existence of the function?

If no log is provided, an abstract-logger instance is used to fill out the expected methods. These express nothing and return void, but do prevent errors.

If the user does not provide a logger (or a logger that does not provide a trace method) does this throw an error?

There is no guarantee or test that a provided logging instance will have the expected methods or that its methods will have the expected signatures/behavior. That does put pressure on developers to use compatible loggers, but that will be the case with or without this PR.

It looks like some of the if statements check the return value and some check the function (like this one did).

Note that there's an inconsistency in how calls on the log object are being made. In some cases there is no 'if' check at all.

The single log.trace check (vs. log.trace()) happens in a type that inherits the same log object used elsewhere, so that appears to be an inconsistency as well.

Copy link
Member

Choose a reason for hiding this comment

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

There is no guarantee or test that a provided logging instance will have the expected methods or that its methods will have the expected signatures/behavior.

On the one hand this could be a problem in theory, on the other hand this hasn't been a problem yet so maybe it isn't in practice.

Note that there's an inconsistency in how calls on the log object are being made. In some cases there is no 'if' check at all.

Yes making it consistent seems like a good reason for this PR.

Copy link
Member

@jsumners jsumners left a comment

Choose a reason for hiding this comment

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

LGTM

@jsumners
Copy link
Member

@UziTech when you get a chance, test out your new publishing privileges with a new patch release (2.2.1).

@UziTech UziTech merged commit ce63a4f into ldapjs:master Nov 13, 2020
@jsumners
Copy link
Member

⚠️ This issue has been locked due to age. If you have encountered a recent
problem that seems to be covered by this issue, please open a new issue.

Please include a minimal reproducible example
when opening a new issue.

@ldapjs ldapjs locked as resolved and limited conversation to collaborators Mar 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants