Facing issue with Python loggin logger for printing object value

Roy Smith roy at panix.com
Sat Dec 29 22:22:16 CET 2012

In article <mailman.1442.1356814265.29569.python-list at python.org>,
 Morten Engvoldsen <mortenengv at gmail.com> wrote:

> It is able to log the message with:
> logger.debug("value of payment_line is " +repr(payment_line))

As a side note, a better way to write that is

logger.debug("value of payment_line is %r", payment_line)

The difference is that the first way, repr(payment_line) is evaluated, 
and the string addition is done, before debug() is called.  Only then 
will it be decided if message should be logged, and if not, it will be 

The second way, payment_line will just get passed to debug().  If the 
message is never logged, repr() will never get called.  Much more 
efficient that way, especially for debug calls which most of the time 
will not get logged.

More information about the Python-list mailing list