-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Make isTraceEnabled calls be computed at build time #12938 #13102
Closed
galderz
wants to merge
1
commit into
quarkusio:master
from
galderz:t_compute_isTraceEnabled_buildtime_12938
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
core/runtime/src/main/java/io/quarkus/runtime/logging/CategoryBuildTimeConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package io.quarkus.runtime.logging; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
@ConfigGroup | ||
public class CategoryBuildTimeConfig { | ||
/** | ||
* Specifies whether <code>isTraceEnabled</code> for a given category will return true or false for a given category. | ||
* This check is computed at build time to provide better hints on code paths that won't be used at runtime. | ||
* | ||
* It's common to see <code>isTraceEnabled</code> calls in sections that include building complex or expensive messages. | ||
* By using <code>isTraceEnabled</code> checks, users can double check that trace enabled before computing such a message. | ||
* Otherwise, complex messages could be constructed but then not used by the logging library if the runtime log level is not trace. | ||
* This build time option controls whether `isTraceEnabled` returns true or false at build time and makes that a constant at runtime, | ||
* irrespective of the runtime log level. | ||
* | ||
* Calls to <code>trace()</code> not preceded by <code>isTraceEnabled</code> are still governed by the runtime log level. | ||
* The message will only be printed if runtime log level for a given category is <code>TRACE</code>. | ||
*/ | ||
@ConfigItem(defaultValue = "false") | ||
public boolean buildTimeTraceEnabled; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 a bit odd in terms of semantics, no? Wouldn't it be far easier for users to understand this feature if the focus was about the trace cathegory as a whole not being something which can be controlled at runtime?
I love the potential of your patch, but in the current shape I'm a bit concerned about it exposing much complexity.
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.
Yeah, it feels a bit odd. I already hinted at this issue here, but @dmlloyd opposed the idea that build time trace configuration should delete all trace calls.
To make this a fully build time feature, aside of what I did in this PR, you'd need to remove
quarkus.log.category.<...>.level=TRACE
option, meaning the ability to set TRACE as a runtime log level.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.
Note that as @dmlloyd said, an option can only either be build time or runtime.
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.
Right, I can see how people would find that odd as well. But personally I think that would be better: this kinda needs a re-definition of a Level to be special.
Ideally the format of configuration could be more specific; allowing the user to choose which runtime configuration elements are made available via an enumeration - I proposed this on the list in the past.
My past proposal was expressed in the area of databases; so in the build time configuration one could, for example, leave MySQL out:
supported_databases={H2,Oracle,PostgreSQL}
then at runtime one has to choose ONE among the enumeration.
Similarly for log levels one could have
< >.level={TRACE,DEBUG,INFO}
or choose
< >.level={DEBUG,INFO}
Which would leave the
TRACE
option out, exluding it from the valid runtime options and therefore folding it as "false" - consistently in all circumstances.IMO it has the following benefits:
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.
We had effectively this feature in the
min-level
configuration. Filtering out arbitrary levels doesn't seem as specifically useful as setting a single bound (and might lead to some confusion). It certainly would be more complex to implement.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.
@dmlloyd raises a valid point here. Although it sounds useful, it also opens up to some potential misuse, e.g. what if the user sets
TRACE,WARN
, do you really only wantTRACE
andWARN
and notDEBUG
,INFO
? If you want to handle ranges, you could add support for..
as an option.min-level
might make more sense, from level X upward. Why was that removed? Was the name confusing? Do you need the flexibility of the enumeration?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 agree,
min-level
looks good. I don't know why it was removed.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.
Looking at
LogConfig
,min-level
seemed to be a runtime option. It got deprecated in #10672, but at first glance I don't see specific reasons on why it got deprecated.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.
It was a build time option originally. It was removed because nobody used it or showed much interest in it.
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'm working on an update to the PR.