Python / Uvicorn Fundamentals Interview Questions
How do you configure Uvicorn logging and access logs?
Uvicorn uses Python's standard logging module with configurable log levels and optional access logging. Log configuration can be provided via CLI flags, environment variables, or a config file.
# Log level options: critical, error, warning, info (default), debug, trace uvicorn main:app --log-level debug # Disable access log (reduces CPU by ~10% under high load) uvicorn main:app --no-access-log # Disable colour in logs (useful for log aggregators) uvicorn main:app --no-use-colors # Use a custom logging config file (JSON, YAML, or INI) uvicorn main:app --log-config logging.yaml # Programmatic log config: uvicorn.run("main:app", log_level="warning", access_log=False) # Production hardened logging: uvicorn main:app \ --log-level warning \ --no-access-log \ --no-use-colors
# logging.yaml - custom Uvicorn log config version: 1 formatters: default: format: "%(asctime)s %(levelname)s %(message)s" use_colors: false access: format: '%(asctime)s %(client_addr)s - "%(request_line)s" %(status_code)s' handlers: default: class: logging.StreamHandler formatter: default access: class: logging.StreamHandler formatter: access loggers: uvicorn: handlers: [default] level: INFO uvicorn.access: handlers: [access] level: INFO propagate: false
Performance tip: disabling access logs (--no-access-log) and setting --log-level warning can reduce CPU usage by up to 10-15% under high concurrency, since log formatting and I/O for every request is eliminated. In production, access logging is often handled at the reverse proxy layer (Nginx/Caddy) instead.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
