-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
f72f9dd
to
5702dc9
Compare
There was a problem hiding this 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.
src/utils/logger.js
Outdated
} 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'); | ||
} |
There was a problem hiding this comment.
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
}
src/utils/logger.js
Outdated
rejectionHandlers: transports, | ||
}); | ||
} else { | ||
logger.warn('Configuration key "logger.sendMailOnError" was not found; the mailer feature of the Logger module won\'t be enabled'); |
There was a problem hiding this comment.
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 🙂
src/utils/logger.js
Outdated
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'); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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”.
- 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 |
src/utils/logger.js
Outdated
@@ -37,4 +21,31 @@ const logger = winston.createLogger({ | |||
rejectionHandlers: transports, | |||
}); | |||
|
|||
if (process.env.SMTP_PASSWORD) { |
There was a problem hiding this comment.
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 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌
No description provided.