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

Make isTraceEnabled calls be computed at build time #12938 #13102

Conversation

galderz
Copy link
Member

@galderz galderz commented Nov 4, 2020

Closes #12938

Logging documentation guide still needs updating, but I've tried to make the javadoc CategoryBuildTimeConfig as explicit as possible.

In essence, this change pushes all isTraceEnabled calls to be computed at build time making them eagerly folded. This means that if no build time trace is enabled, all runtime isTraceEnabled calls will be precomputed to false, leading to the true branches to be dead code eliminated (along with any strings created inside of them). Whether those return true/false are controlled by the newly added build time configuration option.

The only exception are those isTraceEnabled calls made in static blocks or initializing static fields. These will always return true and that's not changing. Any users of isTraceEnabled caching in static fields should be changed.

Note that log.trace() still works as usual. This means that any messages passed are only printed if runtime log level is TRACE.

Finally, note that I've changed slightly the name from my suggestion in here.

TODO:

  • Update documentation (once PR approved).

@galderz galderz requested review from dmlloyd and Sanne November 4, 2020 09:20
* 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.
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member

@Sanne Sanne Nov 4, 2020

Choose a reason for hiding this comment

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

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.

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:

  1. it's clear what the end user is opting for
  2. people who prefer having more options at runtime can have their way if they want to
  3. Clean, precise separation of build-time vs runtime configuration

Copy link
Member

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.

Copy link
Member Author

@galderz galderz Nov 9, 2020

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 want TRACE and WARN and not DEBUG, 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?

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

@galderz galderz Nov 10, 2020

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.

@galderz
Copy link
Member Author

galderz commented Nov 19, 2020

Please see #13376 for a follow up PR with a new solution based on the feedback here.

@galderz galderz closed this Nov 19, 2020
@ghost ghost added the triage/invalid This doesn't seem right label Nov 19, 2020
@galderz galderz deleted the t_compute_isTraceEnabled_buildtime_12938 branch March 18, 2021 09:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage/invalid This doesn't seem right
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TRACE logging improvements
3 participants