A suggestion for an easy logger

Vinay Sajip vinay_sajip at yahoo.co.uk
Sun May 8 08:31:15 EDT 2011


On May 8, 12:21 pm, TheSaint <nob... at nowhere.net.no> wrote:


> First I didn't espect to see much more than my message. I agree that I'm
> very new to the module

You could do

logging.basicConfig(level=logging.DEBUG, format='%(message)s')

to get just the message.

> Second the will terminator appear only to real stdout, or am I doing
> something incorrect?

The terminator is an attribute on the StreamHandler instance, so works
with whatever stream the handler is using. You can't use basicConfig()
directly, if you want to configure the terminator - instead, use
something like

sh = logging.StreamHandler(sys.stdout)
sh.terminator = ''
logging.getLogger().addHandler(sh)

but be sure to execute this code one time only, or you will get
multiple identical messages for a single logging call.

Regards,

Vinay Sajip



More information about the Python-list mailing list