Skip to content

Use lazy (old style %-format) log formatting in the new pylint config #1334

Closed

Description

@sechkova

Description of issue or feature request:
Using f-strings (and all types of string formatting except %-syle) in logging messages is not lazy evaluated so linters "recommend" %-style formatting.

Should we disable the related pylint warnings and use f-strings:

logging-not-lazy
logging-format-interpolation
logging-fstring-interpolation

or adhere to the recommendation.

Current behavior:
Top-level pylintrc disables logging that recommend lazy formatting globally.
New api/pylintrc does not.

Expected behavior:
Decide on a common approach.

Activity

  1. sechkova commented on Apr 6, 2021

    @sechkova
    ContributorAuthor

    An example approach to avoid the warnings while using f-strings which feels more like a workaround: 438c0a0

  2. added
    discussion
    on Apr 6, 2021
  3. jku commented on Apr 7, 2021

    @jku
    Member

    It's annoying to use a different formatting method for logging than anything else but the reasoning is solid... Most of our logging is not in a "hot loop" but some debug logs really might be used quite a lot (and the workaround only hides the warning, not the potential performance issue in those cases).

    I think using %-style is fine for logging: logger.debug("processing, a=%s", a) but it's not a strong opinion -- in the opposite case we may want to do a quick review to identify hottest logging calls though.

  4. changed the title [-]Decide on lazy log lormatting in the new pylint config[/-] [+]Decide on lazy log formatting in the new pylint config[/+] on Apr 7, 2021
  5. sechkova commented on Apr 8, 2021

    @sechkova
    ContributorAuthor

    And then there is this issue when trying to use %-style formatting but you've set up pylint to logging-format-style=new.

  6. jku commented on Apr 9, 2021

    @jku
    Member

    I had understood that using %-style implies means we would need to use logging-format-style=old anyway (or rather not set it as that's the default)? Pylint docs really could have more examples.

  7. jku commented on May 6, 2021

    @jku
    Member

    I'm proposing we use the default logging style, meaning:

    • use logging-format-style=old (which is default value)
    • stop disabling logging-not-lazy (note: this is done only in some experimental client branches -- metadata api itself hasn't needed this because there's zero logging so far 😬 )

    It looks a bit uglier (other string formatting is f-strings but logging is then based on %-formatting) but:

    • it's a common style
    • it's suggested by the google style guide
    • it means we don't have to think about performance when writing logging code
  8. joshuagl commented on May 10, 2021

    @joshuagl
    Member

    Proposal above makes sense to me, if it's what's suggested by the style guide we probably don't even need to capture anything for this? Let's just do what our style guide suggests.

  9. changed the title [-]Decide on lazy log formatting in the new pylint config[/-] [+]Use lazy (old style %-format) log formatting in the new pylint config[/+] on May 11, 2021
  10. added a commit that references this issue on May 11, 2021
    efd412a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions