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

Refactor log level configuration #7695

Merged
merged 7 commits into from Oct 8, 2020
Merged

Conversation

jiv-e
Copy link
Contributor

@jiv-e jiv-e commented Sep 2, 2020

  • Remove STRAPI_LOG_LEVEL environment variable related redundant code.
  • Add helpful error message to the current log level configuration
    system.

Fixes #7673

- Remove STRAPI_LOG_LEVEL environment variable related redundant code.
- Add helpful error message to the current log level configuration
  system.

Signed-off-by: Juho Viitasalo <juho.viitasalo@lildrop.com>
Signed-off-by: Juho Viitasalo <juho.viitasalo@lildrop.com>
@jiv-e jiv-e changed the title Issue/7683 Refactor log level configuration Sep 2, 2020
@codecov
Copy link

codecov bot commented Sep 2, 2020

Codecov Report

Merging #7695 into master will increase coverage by 5.78%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7695      +/-   ##
==========================================
+ Coverage   27.23%   33.01%   +5.78%     
==========================================
  Files        1163     1219      +56     
  Lines       15532    13571    -1961     
  Branches     2411     1349    -1062     
==========================================
+ Hits         4230     4481     +251     
+ Misses       9534     8207    -1327     
+ Partials     1768      883     -885     
Flag Coverage Δ
#front 24.70% <ø> (+5.28%) ⬆️
#unit 54.05% <ø> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...admin/src/containers/LanguageProvider/selectors.js 50.00% <0.00%> (-21.43%) ⬇️
...rapi-admin/admin/src/hooks/useFetchRole/reducer.js 80.00% <0.00%> (-20.00%) ⬇️
...min/admin/src/components/Roles/Permissions/init.js 80.00% <0.00%> (-20.00%) ⬇️
...n/src/components/Users/SelectRoles/utils/styles.js 71.42% <0.00%> (-17.47%) ⬇️
...-admin/admin/src/containers/HomePage/components.js 40.00% <0.00%> (-17.15%) ⬇️
...ents/Webhooks/HeadersInput/utils/getBorderColor.js 50.00% <0.00%> (-16.67%) ⬇️
packages/strapi-admin/services/permission.js 77.57% <0.00%> (-14.00%) ⬇️
.../admin/src/components/Roles/Permissions/reducer.js 85.41% <0.00%> (-13.64%) ⬇️
...t-type-builder/controllers/validation/relations.js 50.00% <0.00%> (-12.50%) ⬇️
.../admin/src/containers/Webhooks/EditView/reducer.js 82.35% <0.00%> (-11.59%) ⬇️
... and 1124 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 005db79...fba9abb. Read the comment docs.

@alexandrebodin
Copy link
Member

Hello, I don't understand what this PR adds ? it is actually a breaking change

@jiv-e
Copy link
Contributor Author

jiv-e commented Sep 2, 2020

Have you read the issue?

PR removes some redundant and confusing code that doesn't do anything anymore. It is not a breaking change.
What it adds is a validation for the log level value and a helpful error message in case the validation fails.

@jiv-e
Copy link
Contributor Author

jiv-e commented Sep 2, 2020

Is it possible this pull request gets accepted? I might need some help passing the code coverage check. I'm not sure what to do with it.

@alexandrebodin
Copy link
Member

That's actually not that simple :).

The logger can be and is used outside of the middleware and might be required (e.g in command line) without the middleware being instantiated. in those usecases the env var is usefull.

We need to make sure the standalone logger offers the previous features it has without have to depend on its log level being instantiate in the middleware.

I Hope that makes sense.

@jiv-e
Copy link
Contributor Author

jiv-e commented Sep 3, 2020

That makes perfect sense. Do you still think it's a good idea to still add the validation part? Do we need to add tests for these features?

In any case when this is settled I'll try to do another pull request to add some docs.

@alexandrebodin
Copy link
Member

Sure doing some validation is alright :) And tests are always welcome 👍

@alexandrebodin alexandrebodin added source: core:strapi Source is core/strapi package issue: enhancement Issue suggesting an enhancement to an existing feature labels Sep 4, 2020
@alexandrebodin
Copy link
Member

Hi @jiv-e will you be able to finish this PR ?

@jiv-e
Copy link
Contributor Author

jiv-e commented Sep 30, 2020

Hi @alexandrebodin,
Yes. I made two more commits. Is this ok?

@@ -25,14 +26,31 @@ module.exports = strapi => {
initialize() {
const { level, exposeInContext, requests } = strapi.config.middleware.settings.logger;

if (level) {
strapi.log.level = level;
const logLevels = ['fatal', 'error', 'warn', 'info', 'debug', 'trace'];
Copy link
Member

Choose a reason for hiding this comment

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

Can you use the levels available at strapi.log.levels to avoid having to maintain this list :)

const logLevels = Object.keys(strapi.log.levels.values);

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 idea.

@alexandrebodin
Copy link
Member

Hey @jiv-e almost there :) WIll you be able to apply the last feedbacks to your PR ?

@jiv-e
Copy link
Contributor Author

jiv-e commented Oct 8, 2020

Done.. I also added validation for STRAPI_LOG_LEVEL.

Copy link
Member

@alexandrebodin alexandrebodin left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: enhancement Issue suggesting an enhancement to an existing feature source: core:strapi Source is core/strapi package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

STRAPI_LOG_LEVEL environment variable is not respected
2 participants