aiohttp icon indicating copy to clipboard operation
aiohttp copied to clipboard

Access log timestamps do not respect daylight savings time

Open arpost opened this issue 7 months ago • 1 comments

Describe the bug

I'm running aiohttp 3.10.11 in a linux docker container in the mountain daylight timezone, and the timestamp that aiohttp inserts into its access logs is in mountain standard time, which is confusing. I see this on Windows desktop and Linux server hosts, and the system time and timezone are correct in the containers as evidenced by running the date command and checking the time in python. The timestamp is in the message part of each log entry, which appears to be generated by aiohttp. For example (the time should be 13:50 and the offset should be -0600):

Image

To Reproduce

  1. Run aiohttp 3.10.11 and python 3.12.7 with default logging setup, for example, logging.basicConfig(level=logging.DEBUG), in a linux docker container.
  2. Observe that the access logs are in standard time not daylight, regardless of whether the user is in daylight savings or not.
  3. Run the date command inside the container to verify that the container's system time has the correct time and time zone, including daylight savings.

Expected behavior

aiohttp access logs should print in the system timezone, or perhaps UTC. If using the system timezone, it's confusing for the logs to use standard time when the system timezone is in daylight savings.

Logs/tracebacks

Should be 08/Jul/2025:13:58:46 -0600:
INFO:aiohttp.access:127.0.0.1 [08/Jul/2025:12:58:46 -0700] "GET /ping HTTP/1.1" 200 166 "-" "curl/7.88.1"

Python Version

$ python --version
Python 3.12.9

aiohttp Version

$ python -m pip show aiohttp
Name: aiohttp
Version: 3.10.11
Summary: Async http client/server framework (asyncio)
Home-page: https://github.com/aio-libs/aiohttp
Author: 
Author-email: 
License: Apache 2
Location: /usr/local/lib/python3.12/site-packages
Requires: aiohappyeyeballs, aiosignal, attrs, frozenlist, multidict, yarl
Required-by: aiohttp-remotes, aiohttp-swagger3, heaserver

multidict Version

$ python -m pip show multidict
Name: multidict
Version: 6.1.0
Summary: multidict implementation
Home-page: https://github.com/aio-libs/multidict
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache 2
Location: /usr/local/lib/python3.12/site-packages
Requires: 
Required-by: aiohttp, heaobject, yarl

propcache Version

$ python -m pip show propcache
Name: propcache
Version: 0.3.2
Summary: Accelerated property cache
Home-page: https://github.com/aio-libs/propcache
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache-2.0
Location: /usr/local/lib/python3.12/site-packages
Requires: 
Required-by: yarl

yarl Version

$ python -m pip show yarl
Name: yarl
Version: 1.18.3
Summary: Yet another URL library
Home-page: https://github.com/aio-libs/yarl
Author: Andrew Svetlov
Author-email: [email protected]
License: Apache-2.0
Location: /usr/local/lib/python3.12/site-packages
Requires: idna, multidict, propcache
Required-by: aio-pika, aiohttp, aiormq, heaobject

OS

Linux docker container (Debian Bookworm), with Linux (Alma Linux 9.5) and Windows (Windows 11 Enterprise 64-bit (10.0.22631)) hosts

Related component

Server

Additional context

No response

Code of Conduct

  • [x] I agree to follow the aio-libs Code of Conduct

arpost avatar Jul 08 '25 21:07 arpost

If you'd like to work on a fix, I'm guessing the problem is here: https://github.com/aio-libs/aiohttp/blob/91108c905f6265bd19e8d1aafbaf2826a33180d2/aiohttp/web_log.py#L141

From the docs:

For the above Timezone constants (altzone, daylight, timezone, and tzname), the value is determined by the timezone rules in effect at module load time or the last time tzset() is called and may be incorrect for times in the past. It is recommended to use the tm_gmtoff and tm_zone results from localtime() to obtain timezone information. https://docs.python.org/3/library/time.html#timezone-constants

I assume the code should be changed to use time.localtime().tm_gmtoff instead.

Dreamsorcerer avatar Jul 09 '25 17:07 Dreamsorcerer