pyGrowler / Growler

A micro web-framework using asyncio coroutines and chained middleware.
http://www.growler.rocks
Apache License 2.0
687 stars 29 forks source link

Replace root logger. #11

Open c-bata opened 8 years ago

c-bata commented 8 years ago

This project is interesting to me.

I think python's library should not use root logger like:

import logging
 logging.warn('this is a warning')

refs: http://pieces.openpolitics.com/2012/04/python-logging-best-practices/

Would you replace root logger like:

from logging import getLogger

logger = getLogger(__name__)
logger.warn('this is a warning')
akubera commented 8 years ago

Thanks for the link! I haven't done a whole lot with the logger module before.

Are you talking specifically about the Logger middleware class? I think I use getLogger for most of the logging in the project.

In your opinion, do do you think that a new log should be created for each incoming connection:

def __call__(self, req, res):
    req.log = getLogger('req')

or as I have it now, where the Logger middleware attaches itself to the request, and is used as a proxy for the internal logger?

def __call__(self, req, res):
    req.log = self

Also, I'm open for suggestions on best ways to format the log prefix, or at least allowing the user to chose the format.

I'll probably visit this after I figure out the event system, the goal being the ability to log the response status code and content size after being sent.