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

Reduce access log overhead when logging is disabled with a logging filter #7251

Closed
wants to merge 15 commits into from

Conversation

bdraco
Copy link
Member

@bdraco bdraco commented Apr 8, 2023

alternative to #7240

What do these changes do?

If the logger was disabled the log message would be formatted and thrown away. Avoid formatting the log message when logging is not enabled at info level.

Are there changes in behavior for the user?

If you are using multiple aiohttp.web.AppRunner in the same python process you must also now pass a unique logger to each because AccessLogger will now attach a filter which affects the state of any logger object passed in and is not re-entrant.

Consumers of AccessLogger MUST use a new unique logger as the AccessLogger will now add logging filter to any existing logger that is passed in which will affect logging for all handlers attached to that logger. Be sure to generate a unique logger object for each instance of AccessLogger. It is important the logger is unique because if other code is using the same logger, the logging filter will likely raise an exception or mutate the log messages in an unexpected way.

        log = logging.getLogger("my_unique_logger_per_instance_of_aiohttp")
        log_format = "%a %{User-Agent}i"
        access_logger = AccessLogger(log, log_format)
        access_logger.log(request, response, time)

If multiple aiohttp instances use the same logger object then the log filter will be attached multiple times which will lead to undefined behavior.

Related issue number

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES folder
    • name it <issue_id>.<type> for example (588.bugfix)
    • if you don't have an issue_id change it to the pr id after creating the pr
    • ensure type is one of the following:
      • .feature: Signifying a new feature.
      • .bugfix: Signifying a bug fix.
      • .doc: Signifying a documentation improvement.
      • .removal: Signifying a deprecation or removal of public API.
      • .misc: A ticket has been closed, but it is not of interest to users.
    • Make sure to use full sentences with correct case and punctuation, for example: "Fix issue with non-ascii contents in doctest text files."

bdraco and others added 11 commits March 23, 2023 08:35
If the logger was disabled the log message would be
formatted and thrown away. Avoid formatting the log
message when logging is not enabled at info level.
Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Apr 8, 2023
@bdraco bdraco changed the title Reduce access log overhead when logging is disabled Reduce access log overhead when logging is disabled with a logging filter Apr 8, 2023
@bdraco
Copy link
Member Author

bdraco commented Apr 8, 2023

After writing out Are there changes in behavior for the user? it seems like the side effects of this change are not going to be received well so I think this path doesn't have a way forward.

@bdraco bdraco closed this Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant