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

Allow run_app(access_log=None) #3504

Merged
merged 4 commits into from
Jan 9, 2019
Merged

Allow run_app(access_log=None) #3504

merged 4 commits into from
Jan 9, 2019

Conversation

hynek
Copy link
Contributor

@hynek hynek commented Jan 8, 2019

What do these changes do?

The docs suggest that you can disable request logging by passing access_log=None to run_app.

However:

  1. It breaks when loop's debug is True
  2. The type stubs don't reflect that

This PR fixes both.

Are there changes in behavior for the user?

Documented behavior works under more conditions now. :)

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • 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."

@hynek hynek requested a review from asvetlov as a code owner January 8, 2019 10:41
CHANGES/3504.bugfix Outdated Show resolved Hide resolved
handle_signals: bool=True,
reuse_address: Optional[bool]=None,
reuse_port: Optional[bool]=None) -> None:
"""Run an app locally"""
loop = asyncio.get_event_loop()

# Configure if and only if in debugging mode and using the default logger
if loop.get_debug() and access_log.name == 'aiohttp.access':
if loop.get_debug() and access_log and access_log.name == 'aiohttp.access':
Copy link
Member

Choose a reason for hiding this comment

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

maybe

Suggested change
if loop.get_debug() and access_log and access_log.name == 'aiohttp.access':
if loop.get_debug() and getattr(access_log, 'name', None) == 'aiohttp.access':

Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

LGTM anyway

@codecov-io

This comment has been minimized.

@@ -269,7 +269,7 @@
backlog: int=128,
access_log_class: Type[AbstractAccessLogger]=AccessLogger,
access_log_format: str=AccessLogger.LOG_FORMAT,
access_log: logging.Logger=access_logger,
access_log: Optional[logging.Logger]=access_logger,
Copy link
Member

Choose a reason for hiding this comment

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

why do u use Optional, and when access_log should be None?

Copy link
Member

Choose a reason for hiding this comment

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

i just don't understand when u need to drop logging :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Firstly, this is just an adoption of the stubs to reflect existing docs, secondly I ask myself the vice versa question every time I try to get rid of some framework's logging. I have “dumb” HTTP logs in my load balancer and I want my applications to have only structured application logs.

Copy link
Member

Choose a reason for hiding this comment

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

The load balancer is story about production, right? do u use debug mode for production?
Now, u can put your custom logger and this should solve your problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't about my problems, this is about making the code do what the docs say. :)

Copy link
Member

Choose a reason for hiding this comment

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

so maybe the problem is not in the code and in the documentation :)
I don't find any test for this behavior and this feature never worked. I am not sure that this feature is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It worked when debug was off which is the normal case. I ran into the edge case of debug=True thanks to mypy.

Copy link
Member

Choose a reason for hiding this comment

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

You are right without mypy all is fine. I think will be cool have some test for this case.

@asvetlov asvetlov merged commit c562ffe into aio-libs:master Jan 9, 2019
@asvetlov
Copy link
Member

asvetlov commented Jan 9, 2019

Thanks!

asvetlov pushed a commit that referenced this pull request Jan 9, 2019
* Mark access_log as optional

* Make access_log=None work in debug mode
(cherry picked from commit c562ffe)

Co-authored-by: Hynek Schlawack <hs@ox.cx>
asvetlov added a commit that referenced this pull request Jan 9, 2019
* Mark access_log as optional

* Make access_log=None work in debug mode
(cherry picked from commit c562ffe)

Co-authored-by: Hynek Schlawack <hs@ox.cx>
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Jan 9, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bot:chronographer:provided There is a change note present in this PR bug outdated server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants