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

Add warning log for disabled Logger mailer due to missing config #3

Merged
merged 5 commits into from
Feb 15, 2024

Conversation

Ndpnt
Copy link
Member

@Ndpnt Ndpnt commented Feb 15, 2024

No description provided.

@Ndpnt Ndpnt force-pushed the warn-logger-mailer-not-enabled branch from f72f9dd to 5702dc9 Compare February 15, 2024 10:09
@clementbiron clementbiron self-requested a review February 15, 2024 13:08
Copy link
Member

@MattiSG MattiSG left a comment

Choose a reason for hiding this comment

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

Good catch!

I would prefer we only log a warning in case the config is set but the env var is missing. The suggested implementation makes the assumption that the user always wants to send emails, which might not be the case.

Comment on lines 44 to 49
} else {
logger.warn('Configuration key "logger.sendMailOnError" was not found; the mailer feature of the Logger module won\'t be enabled');
}
} else {
logger.warn('Environment variable "SMTP_PASSWORD" was not found; the mailer feature of the Logger module won\'t be enabled');
}
Copy link
Member

Choose a reason for hiding this comment

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

For readability, I would suggest reverting the condition:

if (!precondition) {
  logger.warn('Precondition not met');
} else { // of course, if possible, do an early exit instead
  // do normal job
}

rejectionHandlers: transports,
});
} else {
logger.warn('Configuration key "logger.sendMailOnError" was not found; the mailer feature of the Logger module won\'t be enabled');
Copy link
Member

Choose a reason for hiding this comment

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

Why is that now a warning? I would assume that if users does not set up this config key, they don't want the mailer logger to be set up 🙂

logger.warn('Configuration key "logger.sendMailOnError" was not found; the mailer feature of the Logger module won\'t be enabled');
}
} else {
logger.warn('Environment variable "SMTP_PASSWORD" was not found; the mailer feature of the Logger module won\'t be enabled');
Copy link
Member

Choose a reason for hiding this comment

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

I believe we should log this warning only if logger.sendMailOnError is set up: if there is no intention to send an email anyway, then the missing env variable is not an issue.

CHANGELOG.md Outdated

### Added

- Add warning log for disabled Logger mailer due to missing config
Copy link
Member

Choose a reason for hiding this comment

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

This is accurate; I just suggest focusing on the impact for end users rather than on the technical description: “log emails cannot be sent” rather than “disabled Logger mailer”.

Suggested change
- Add warning log for disabled Logger mailer due to missing config
- Log a warning in case log emails cannot be sent because of a missing config

@@ -37,4 +21,31 @@ const logger = winston.createLogger({
rejectionHandlers: transports,
});

if (process.env.SMTP_PASSWORD) {
Copy link
Member

Choose a reason for hiding this comment

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

SMTP servers can be set up to send without password authentication, for example if they are on the same private network. It thus seems a potential legit setup for SMTP_PASSWORD to be undefined. In order to keep this relevant check and warning, I suggest that we check explicitly if it is undefined rather than falsy, so that users having no password authentication can set SMTP_PASSWORD to the empty string 🙂

Copy link
Member

@MattiSG MattiSG left a comment

Choose a reason for hiding this comment

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

👌

@Ndpnt Ndpnt merged commit ef83cc8 into main Feb 15, 2024
4 checks passed
@MattiSG MattiSG deleted the warn-logger-mailer-not-enabled branch June 12, 2024 08:57
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.

3 participants