[Python-Dev] transitioning from % to {} formatting

Vinay Sajip vinay_sajip at yahoo.co.uk
Thu Oct 1 16:37:29 CEST 2009

Antoine Pitrou <solipsis <at> pitrou.net> writes:

> There's another possibility, which is to build the wrapping directly around the
> logger. That is, if I want a %-style logger, I do:
>    logger = logging.getLogger("smtp")
>    logger.debug("incoming email from %s", sender_address)
> and I want a {}-style logger, I do:
>    logger = logging.getLogger("smtp", style="{}")
>    logger.debug("incoming email from {addr}", addr=sender_address)
> (of course, different users of the "smtp" logger can request different
> formatting styles when calling getLogger().)

There's a LoggerAdapter class already in the system which is used to wrap
loggers so that additional contextual information (e.g. network or database
connection information) can be added to logs. The LoggerAdapter could fulfill
this "wrapping" function.

> We could combine the various proposals to give users flexible APIs. Of course,
> it generally smells of "there's more than one way to do it".

Yeah, that bothers me too.

> > It's the Rumsfeldian "We don't know what we don't know" 
> Is this guy in the Python community? 

Not sure, but I believe he's a piece of work and not a guy to get on the wrong
side of ;-)


Vinay Sajip

More information about the Python-Dev mailing list