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: The default log levels for different NODE_ENVs are surprising #704

Closed
theneva opened this issue Feb 3, 2021 · 1 comment · Fixed by #803
Closed

fix: The default log levels for different NODE_ENVs are surprising #704

theneva opened this issue Feb 3, 2021 · 1 comment · Fixed by #803
Labels

Comments

@theneva
Copy link
Contributor

theneva commented Feb 3, 2021

Hi!

I set the environment variable NODE_ENV to production in my Docker image to avoid installing dev dependencies and having libraries like envalid work as intended.

As a side effect of this setting, Unleash sets log4js's log level to ERROR:

unleash/lib/logger.js

Lines 5 to 13 in 3a983d2

function getDefaultLogProvider() {
let level;
if (process.env.NODE_ENV === 'production') {
level = log4js.levels.ERROR.levelStr;
} else if (process.env.NODE_ENV === 'test') {
level = log4js.levels.FATAL.levelStr;
} else {
level = log4js.levels.DEBUG.levelStr;
}

I find this behaviour quite surprising. I'm pretty much always interested in INFO and up even in a production environment.

I also find it strange that test environments only log FATAL messages, even though the log provider validation doesn't check for an implementation of fatal logging:

unleash/lib/logger.js

Lines 37 to 45 in 3a983d2

function validateLogProvider(provider) {
validate(typeof provider === 'function', 'Provider needs to be a function');
const logger = provider('unleash:logger');
validate(typeof logger.debug === 'function', 'Logger must implement debug');
validate(typeof logger.info === 'function', 'Logger must implement info');
validate(typeof logger.warn === 'function', 'Logger must implement warn');
validate(typeof logger.error === 'function', 'Logger must implement error');
}

Am I missing a way to override the log level in a production environment without providing my own logger implementation? If not, exposing a config option and/or an env var (for example, LOG_LEVEL) would be great!

@ivarconr ivarconr changed the title The default log levels for different NODE_ENVs are surprising fix: The default log levels for different NODE_ENVs are surprising Feb 5, 2021
@theneva
Copy link
Contributor Author

theneva commented Feb 8, 2021

As a side note, we set NODE_ENV to "production" in the official Docker image, which kills all logging you might expect to see from the app when reading the docs Unleash/unleash-docker#36 (comment)

(Maybe it's better to RUN NODE_ENV=production npm ci instead of doing ENV NODE_ENV=production…)

@ivarconr ivarconr added the bug label Mar 5, 2021
ivarconr added a commit that referenced this issue Apr 23, 2021
ivarconr added a commit that referenced this issue Apr 23, 2021
ivarconr added a commit that referenced this issue Apr 23, 2021
Tymek pushed a commit that referenced this issue Aug 26, 2022
refactor: use copy library and add explicit export
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants