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

Load dot env before utils, allow setting STRAPI_LOG_LEVEL in env file #6693

Open
aksdevac opened this issue Jun 16, 2020 · 5 comments
Open

Load dot env before utils, allow setting STRAPI_LOG_LEVEL in env file #6693

aksdevac opened this issue Jun 16, 2020 · 5 comments

Comments

@aksdevac
Copy link
Contributor

@aksdevac aksdevac commented Jun 16, 2020

Describe the bug
If I set STRAPI_LOG_LEVEL variable in .env file it does not work because log utils are loaded before dotenv

Steps to reproduce the behavior

  1. Set STRAPI_LOG_LEVEL in env file & see if it works

Expected behavior
Env vars from .env file should be loaded before starpi-utils logger

System

  • Node.js version: 12.18.0
  • NPM version: Yarn 1.22.x
  • Strapi version: 3.0.2
  • Database: Mongo
  • Operating system: MacOS 10.15.5
@lauriejim
Copy link
Member

@lauriejim lauriejim commented Jun 16, 2020

Hello! thank you for reporting that, can you please submit a PR.
I will appreciate your contribution on this point.
Thank you.

@akhilmhdh
Copy link
Contributor

@akhilmhdh akhilmhdh commented Jun 16, 2020

@lauriejim @aksdevac STRAPI_LOG_LEVEL does work finely inside the logger of strapi. I had checked the variable outputs. The logs is getting printed due to logger middleware which has default value as debug. To change the level, in create/existing config/middleware.js add like this.
module.exports = { //... settings: { logger: { level: "error" }, }, };

It can be also env.
Doc link:
https://strapi.io/documentation/v3.x/concepts/middlewares.html#core-middleware-configurations)

If you want I can submit a PR that checks for the process.env.STRAPI_LOG_LEVEL and take that as log level.

@aksdevac
Copy link
Contributor Author

@aksdevac aksdevac commented Jun 17, 2020

@lauriejim Hi, submitted PR #6701 but it might not fix issue, as middleware is overriding default log level as mentioned in PR & by @akhilmhdh, but can be used for STRAPI_LOG_TIMESTAMP, STRAPI_LOG_PRETTY_PRINT etc

@rylax
Copy link

@rylax rylax commented Feb 21, 2021

There is another way of making this work. Export your middleware.js with the env object and pass it a default. This way you can make sure your process.env will override it:

module.exports = ({ env }) => ({
    settings: {
        logger: {
            level: env('STRAPI_LOG_LEVEL', 'debug')
        }
    }
})
@derrickmehaffy
Copy link
Member

@derrickmehaffy derrickmehaffy commented Feb 22, 2021

There is another way of making this work. Export your middleware.js with the env object and pass it a default. This way you can make sure your process.env will override it:

module.exports = ({ env }) => ({
    settings: {
        logger: {
            level: env('STRAPI_LOG_LEVEL', 'debug')
        }
    }
})

This is the correct method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants