Overriding a global

Jean-Michel Pichavant jeanmichel at sequans.com
Mon Dec 12 06:13:33 EST 2011


Roy Smith wrote:
> MRAB <python at mrabarnett.plus.com> wrote:
>
>   
>> or use 'globals':
>>
>>      def function(self):
>>          logger = globals()['logger'].getChild('function')
>>          logger.debug('stuff')
>>          logger.debug('other stuff')
>>     
>
> Ah-ha!  That's precisely what I was looking for.  Much appreciated.
>   
Using the same name for 2 different objects is a bad idea in general.
In debug mode, i.e. the logger is configured with the debug level, you 
could simply write down the filename and the line number on your log 
events.

formatter = logging.Formatter('%(name)s : %(filename)s %(lineno)s  
%(message)s')

So you can easily see who logged what (if I'm not wrong, that's what 
you're trying to do)

JM



More information about the Python-list mailing list