-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Make access log use local time with timezone #3860
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3860 +/- ##
=========================================
- Coverage 97.96% 97.86% -0.1%
=========================================
Files 43 43
Lines 8588 8590 +2
Branches 1373 1373
=========================================
- Hits 8413 8407 -6
- Misses 71 78 +7
- Partials 104 105 +1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test and changelog record would be awesome!
I read the test codes about web_log.py. but how to test this since there are expected and extras dicts in it? |
@NewUserHa google |
No need for monkey-patching here |
I know. the problem is: def test_access_logger_atoms(mocker) -> None:
utcnow = datetime.datetime(1843, 1, 1, 0, 30)
mock_datetime = mocker.patch("aiohttp.datetime.datetime")
mock_getpid = mocker.patch("os.getpid")
mock_datetime.utcnow.return_value = utcnow
mock_getpid.return_value = 42
log_format = '%a %t %P %r %s %b %T %Tf %D "%{H1}i" "%{H2}i"'
mock_logger = mock.Mock()
access_logger = AccessLogger(mock_logger, log_format)
request = mock.Mock(headers={'H1': 'a', 'H2': 'b'},
method="GET", path_qs="/path",
version=(1, 1),
remote="127.0.0.2")
response = mock.Mock(headers={}, body_length=42, status=200)
access_logger.log(request, response, 3.1415926)
assert not mock_logger.exception.called
expected = ('127.0.0.2 [01/Jan/1843:00:29:56 +0000] <42> '
'GET /path HTTP/1.1 200 42 3 3.141593 3141593 "a" "b"')
extra = {
'first_request_line': 'GET /path HTTP/1.1',
'process_id': '<42>',
'remote_address': '127.0.0.2',
'request_start_time': '[01/Jan/1843:00:29:56 +0000]',
'request_time': 3,
'request_time_frac': '3.141593',
'request_time_micro': 3141593,
'response_size': 42,
'response_status': 200,
'request_header': {'H1': 'a', 'H2': 'b'},
}
mock_logger.info.assert_called_with(expected, extra=extra) I meant, can it test/assert the timezone? because request_start_time is fixed, then the expected always will be the same |
well. Will adding tz to |
I guess yes, please extract checking of |
Co-Authored-By: Sviatoslav Sydorenko <[email protected]>
Co-Authored-By: Sviatoslav Sydorenko <[email protected]>
Co-Authored-By: Sviatoslav Sydorenko <[email protected]>
tests/test_web_log.py
Outdated
mock_datetime.utcnow.return_value = utcnow | ||
mock_getpid.return_value = 42 | ||
log_format = '%a %t %P %r %s %b %T %Tf %D "%{H1}i" "%{H2}i"' | ||
@pytest.fixture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure that skip marker doesn't work on fixtures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but if use parameterizing, it seems to have to use fixtrue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I'm talking about that the marked is supposed to skip things depending on the condition (PyPy). And if you apply it to fixtures, not test functions it just doesn't have any effect meaning it will never skip any tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. I need to check some documents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, it's okay since you removed the fixture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(needs fixing to actually work)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
It should be good to merge once CI jobs show up as green. |
Thanks, @NewUserHa! |
thanks for your review and merge. |
Because you submitted the PR against devel which is future 4.0. 3.5 is in its own stable branch. And yes, the changelog fragment is needed. We just missed it. So please submit a follow-up PR with it. |
release 3.5 against test_web_log.py 3.5. |
I use version 3.7.3 and the timestamp in access log still in UTC timezone |
(cherry picked from commit eb9aa22) Co-authored-by: NewUserHa <[email protected]>
Thanks for the reminder. We missed to backport the PR. #5351 should land at 3.8 |
(cherry picked from commit eb9aa22) Co-authored-by: NewUserHa <[email protected]> Co-authored-by: NewUserHa <[email protected]>
PR aio-libs#3860 by @NewUserHa Co-Authored-By: Sviatoslav Sydorenko <[email protected]>
## What do these changes do? Backport #3860 to the `3.9` branch with the latest changes from `master` Use changelog fragment from #3860. It was only ever merged into `master` and `3.8`. _This also resolves a DeprecationWarning for Users when running Python 3.12 -> `utcnow`._ --------- Co-authored-by: NewUserHa <[email protected]> Co-authored-by: Sviatoslav Sydorenko <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
What do these changes do?
change access log use localtime and timezone instead all uctime
Are there changes in behavior for the user?
show localtime instead utctime if turn on access log
Related issue number
Fixes #3853
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.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.