-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Show requests log in terminal #2952
Comments
You need to setup access logger: https://docs.aiohttp.org/en/stable/logging.html#access-logs All-logging-by-default is too annoying, that's why aiohttp has a separate API for it |
Well, after that, will it be shown in terminal for each requests? |
Yes. |
I'm new to aiohttp, can you show me how to configure that? |
The question is out of aiohttp scope. |
Actually your aiohttp logging docs implies there's extra stuff or a best practice to do logging for aiohttp apps and thus creates confusion for the issue. I just ran into the exact same issue, especially since the documentation actually explicitly says logging is turned on by default but nothing comes out. And anyone who has ever written a web server or was working to get familiar with a web framework has needed this ability for initial tests/debugging - so an example of the simplest way to turn this on for web development would actually be quite valuable in the documentation. I thought for a moment that the logging utilities might be implemented as a context or something but that doesn't seem to be the case. |
For debugging purposes, I made this little bash command that will run my app (listing_server.listing_app) with debug logging turned on. It should make it obvious how to use basic logging in an aiohttp server context. python -c "import logging; from aiohttp import web; from listing_server import *; logging.basicConfig(level=logging.DEBUG); web.run_app(listing_app);" |
Logging setup is a very complicated question: different apps require different settings. If you have an idea for documentation improvement -- please make a Pull Request. |
Actually, access log to the stdout is standard for any HTTP servers. |
Really? |
AFAIR flask prints out access logs too |
Aha, http://flask.pocoo.org/docs/1.0/logging/#default-configuration |
No real answer is given. Or none that is intelligible to this reader. Give clear minimal instructions for running your web app with access logging please. |
Here's an example that worked for my situation import logging
stdio_handler = logging.StreamHandler()
stdio_handler.setLevel(logging.INFO)
_logger = logging.getLogger('aiohttp.access')
_logger.addHandler(stdio_handler)
_logger.setLevel(logging.DEBUG) app = web.Application(logger=_logger)
runner = web.AppRunner(app)
await runner.setup()
site = web.TCPSite(runner, args.host, args.port_rpc)
await site.start() and the output now includes lines like
|
hope there's a document enhancement or an aiohttp enhancement for this. |
Champion is welcome! |
I have no idea how to modify aiohttp to behavior like others like ps. the PR for debug flag to run_app cant pass test. do you have any idea? |
Long story short
I want the log display in terminal feature like django
Expected behaviour
When running "python main.py", any hit on URL endpoint should log the info in the terminal.
For example:
======== Running on http://0.0.0.0:8095 ========
(Press CTRL+C to quit)
[21:36:52] 127.0.0.1 [23/Apr/2018:15:36:52 +0000] "GET / HTTP/1.1" 200 183 "-" "PostmanRuntime/6.4.1"
Actual behaviour
No log info display
Your environment
Windows 8.1, 64 Bit, Python 3.6
The text was updated successfully, but these errors were encountered: