Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.42!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news-transit.tcx.org.uk!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'debug': 0.03; 'one?': 0.05; 'suppose': 0.05; '__name__': 0.09; 'settings,': 0.09; 'def': 0.13; "'__main__':": 0.16; 'codebase,': 0.16; 'expected,': 0.16; 'subject:issues': 0.16; 'subject:logging': 0.16; 'yet.': 0.18; 'maybe': 0.21; 'somewhere': 0.23; 'code': 0.25; 'import': 0.27; 'script': 0.28; 'class': 0.29; 'example': 0.29; 'imported': 0.30; 'specified': 0.31; 'does': 0.32; 'skip:l 30': 0.32; 'idea': 0.32; "can't": 0.32; 'message-id:@gmail.com': 0.33; 'header:User- Agent:1': 0.33; 'instead': 0.33; 'there': 0.33; 'to:addr:python- list': 0.34; 'root': 0.34; 'running': 0.35; 'something': 0.35; 'modules': 0.35; 'sets': 0.35; 'unless': 0.35; 'however,': 0.36; 'but': 0.37; 'received:google.com': 0.37; 'another': 0.37; 'think': 0.37; 'skip:_ 10': 0.37; 'received:10.0.0': 0.38; 'received:209.85': 0.38; 'should': 0.39; 'else': 0.39; 'why': 0.39; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'happens': 0.40; 'below': 0.63; 'act': 0.65; 'become': 0.69; 'message")': 0.84; 'wish.': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=ycGqwPdSfjaeTpBWSTtCFZgL/EBzJeAn4kGK7K/Z9ls=; b=B6oIYXqhdd66MD5wRxGx9X5flRW3r2gUmPGNr2JZFN4woxm4ZUoTqCEzSQxB5PCr6G VDv8+fAdPlxLTDh4r8ia/9HmhGSm/GziU+EaeLw0L3i1QupZ/0xDDDBwiUdJ9hdLZ2rN pge0KjtLpiQMok1FIuz8Lfnr5/7b+zdwikCBQ= Date: Tue, 13 Dec 2011 15:42:49 +0000 From: Andrea Crotti User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111108 Thunderbird/8.0 MIME-Version: 1.0 To: python-list@python.org Subject: logging issues Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323790975 news.xs4all.nl 6849 [2001:888:2000:d::a6]:58888 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17141 I think is simple but I can't get it to work as I wish. Suppose I have a big application, my idea is that the running script sets a global logging level and then all the imported modules would act consequently. In my codebase, however, unless I set the level for each of the loggers I don't get the debug messages, not really sure why yet. To check if I understood, logging.getLogger() returns the root logger, and every other logger should inherit its settings, is that correct? What happens if there is another logging.getLogger() somewhere else in the code after the initialization? Does that become the root logger overriding the old one? The example below instead works as expected, so maybe is something with my codebase... # m1.py import logging logging.basicConfig() # if no name is specified return the root logger, that's how it works logger = logging.getLogger() logger.setLevel(logging.DEBUG) class ToLogEvents(object): def __init__(self): self.logger = logging.getLogger('ToLogEvents') def important(self): self.logger.warning("This is an important message") self.logger.debug("debug message") if __name__ == '__main__': logger.debug("debug from m1") from m2 import logging_function logging_function() t = ToLogEvents() t.important() # m2.py import logging logger = logging.getLogger(__name__) def logging_function(): logger.debug("debug message") logger.info("info message")