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

Implement Logger.isLevelEnabled #144033

Merged
merged 5 commits into from
Oct 28, 2022

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Oct 26, 2022

Summary

Fix #144002

Implement Logger.isLevelEnabled (similar to log4j's isEnabled / isInfoEnabled and so on...), to allow to wrap log writing inside conditional blocks.

if(logger.isLevelEnabled('debug')) {
  const debugData = someExpensiveDebugOperation();
  logger.debug('here is the debug data', debugData);
}

@pgayvallet pgayvallet added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:skip Skip the PR/issue when compiling release notes Feature:Logging labels Oct 26, 2022
@pgayvallet pgayvallet marked this pull request as ready for review October 26, 2022 18:08
@pgayvallet pgayvallet requested review from a team as code owners October 26, 2022 18:08
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@botelastic botelastic bot added the Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) label Oct 26, 2022
Copy link
Member

@afharo afharo left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +444 to +452
for (const logLevel of orderedLogLevels) {
it(`returns the correct value for a '${logLevel.id}' level logger`, () => {
const levelLogger = new BaseLogger(context, logLevel, appenderMocks, factory);
for (const level of orderedLogLevels) {
const levelEnabled = logLevel.supports(level);
expect(levelLogger.isLevelEnabled(level.id)).toEqual(levelEnabled);
}
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
for (const logLevel of orderedLogLevels) {
it(`returns the correct value for a '${logLevel.id}' level logger`, () => {
const levelLogger = new BaseLogger(context, logLevel, appenderMocks, factory);
for (const level of orderedLogLevels) {
const levelEnabled = logLevel.supports(level);
expect(levelLogger.isLevelEnabled(level.id)).toEqual(levelEnabled);
}
});
}
it.each(orderedLogLevels)(`returns the correct value for a '$id' level logger`, (logLevel) => {
const levelLogger = new BaseLogger(context, logLevel, appenderMocks, factory);
for (const level of orderedLogLevels) {
const levelEnabled = logLevel.supports(level);
expect(levelLogger.isLevelEnabled(level.id)).toEqual(levelEnabled);
}
});

Copy link
Member

@nchaulet nchaulet left a comment

Choose a reason for hiding this comment

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

LGTM this is exactly what we need in Fleet.

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

Response Ops changes LGTM.

Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

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

LGTM

@pgayvallet
Copy link
Contributor Author

@elasticmachine merge upstream

@pgayvallet pgayvallet enabled auto-merge (squash) October 28, 2022 06:18
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/logging 37 38 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
core 369.4KB 369.4KB +36.0B
expressions 98.0KB 98.1KB +22.0B
total +58.0B
Unknown metric groups

API count

id before after diff
@kbn/logging 30 32 +2
core 2700 2702 +2
total +4

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@pgayvallet pgayvallet merged commit 4ab9ef5 into elastic:main Oct 28, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) Feature:Logging release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v8.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logging: add Logger.isLevelEnabled API
10 participants