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

Improve access logging #572

Merged
merged 8 commits into from
Oct 22, 2015
Merged

Improve access logging #572

merged 8 commits into from
Oct 22, 2015

Conversation

redixin
Copy link
Contributor

@redixin redixin commented Oct 17, 2015

Introduce class AccessLogger. Instance of this class is
constructed by passing log_format, and used to log messages
according to this format.

Usage:

        log = logging.getLogger("spam")
        log_format = "%a %{User-Agent}i"
        access_logger = AccessLogger(log, log_format)
        access_logger.log(message, environ, response, transport, time)

Use this object in ServerHttpProtocol for logging.

Also closed #458

Introduce class AccessLogger. Instance of this class is
constructed by passing log_format, and used to log messages
according to this format.

Sample usage:

    log = logging.getLogger("spam")
    access_logger = AccessLogger(log, "%a %{User-Agent}i")
    access_logger.log(message, environ, response, transport, time)

Use this object in ServerHttpProtocol for logging.
Sergey Skripnick added 5 commits October 17, 2015 22:23
The common time format for logs is:

[day/month/year:hour:minute:second zone]
day = 2*digit
month = 3*letter
year = 4*digit
hour = 2*digit
minute = 2*digit
second = 2*digit
zone = (`+' | `-') 4*digit
To be consitent with apache, %b should contain output body length
without headers.

Also add %O variable which contain full output length.
Create AccessLogger instance in RequestHandlerFactory constructor. This
avoids initializing AccessLogger per each connection.
"""Return a dash instead of raising KeyError"""

def __getitem__(self, key):
val = dict.get(self, key.upper())
Copy link
Member

Choose a reason for hiding this comment

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

Use upstr(key) instead of key.upper() call.

Sergey Skripnick added 2 commits October 21, 2015 23:56
Use cache for faster AccessLogger initialization.
Optimize logging process.
@redixin
Copy link
Contributor Author

redixin commented Oct 21, 2015

New patch added:

    Restore original signature of ServerHttpProtocol

    Use cache for faster AccessLogger initialization.
    Optimize logging process.

Now AccessLogger object is constructed in ServerHttpProtocol.__init__ but thanks to caching it quite fast. (At least 1% faster then master)

I can try to move AccessLogger instantiation out of constructor later.

asvetlov added a commit that referenced this pull request Oct 22, 2015
@asvetlov asvetlov merged commit 76bfd69 into aio-libs:master Oct 22, 2015
@asvetlov
Copy link
Member

Cool!
Would you write doc chapter about logging setup.
I think it should be toplevel rst file with instructions for logging setup and description for available format options

@lock
Copy link

lock bot commented Oct 29, 2019

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 Oct 29, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] Gunicorn worker logs are incorrect
2 participants