Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'debug': 0.03; 'mrab': 0.04; 'mode,': 0.07; 'filename': 0.09; 'wrong,': 0.09; 'def': 0.13; 'do)': 0.16; 'general.': 0.16; 'roy': 0.16; 'subject:Overriding': 0.16; 'subject:global': 0.16; 'cc:addr :python-list': 0.16; 'wrote:': 0.18; 'level,': 0.18; 'cc:no real name:2**0': 0.20; 'trying': 0.21; 'header:In-Reply-To:1': 0.22; 'cc:2**0': 0.24; "i'm": 0.26; 'cc:addr:python.org': 0.29; 'skip:% 10': 0.30; 'skip:g 40': 0.30; 'objects': 0.32; 'idea': 0.32; 'header:User-Agent:1': 0.33; 'events.': 0.37; 'could': 0.37; 'using': 0.38; 'configured': 0.38; 'i.e.': 0.39; 'appreciated.': 0.39; 'your': 0.61; 'received:62': 0.70 X-IronPort-AV: E=Sophos;i="4.71,337,1320620400"; d="scan'208";a="39000" X-Virus-Scanned: amavisd-new at zimbra.sequans.com Date: Mon, 12 Dec 2011 12:13:33 +0100 From: Jean-Michel Pichavant User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) MIME-Version: 1.0 To: Roy Smith Subject: Re: Overriding a global References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323688423 news.xs4all.nl 6864 [2001:888:2000:d::a6]:37983 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17030 Roy Smith wrote: > MRAB 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