logging messages in imported modules not showing up
From: Erick Bodine (erick_bodine_at_comcast.net)
Date: 03/09/04
- Next message: Dang Griffith: "Re: URGENT: REALLY NEED HELP: Feel Helpless"
- Previous message: biner: "getting size of gif"
- Next in thread: Vinay Sajip: "Re: logging messages in imported modules not showing up"
- Reply: Vinay Sajip: "Re: logging messages in imported modules not showing up"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 9 Mar 2004 11:41:37 -0800
I have a script that sets up logging at startup, imports a module
(module1) which itself imports another module (module2).
The problem is that if I run script.py, I see the following. I never
see the 'MyClass2 initialized' log message from module2??
2004-03-09 12:15:18,348 DEBUG [script:15] logging enabled
2004-03-09 12:15:18,348 DEBUG [module1:12] MyClass initialized
2004-03-09 12:15:18,348 DEBUG [module2:14] MyClass2 do_something
--------------
script.py
-------------
import logging, module1
def main():
# setup logging
log = logging.getLogger('myapp')
handler = logging.StreamHandler()
log.setLevel(logging.DEBUG)
format = logging.Formatter("%(asctime)s %(levelname)-3s " \
"[%(module)s:%(lineno)d] %(message)s")
handler.setFormatter(format)
log.addHandler(handler)
log.debug("logging enabled")
my = module1.MyClass()
if __name__ == '__main__':
main()
--------------
module1.py
--------------
import logging, module2
log = logging.getLogger('myapp')
class MyClass:
def __init__(self):
log.debug("MyClass initialized")
def something(self):
my = module2.MyClass2()
my.do_something()
-------------
module2.py
-------------
import logging
log = logging.getLogger('myapp')
class MyClass2:
def __init__(self):
log.debug("MyClass2 initialized")
def do_something(self):
log.debug("In MyClass2 do_something")
- Next message: Dang Griffith: "Re: URGENT: REALLY NEED HELP: Feel Helpless"
- Previous message: biner: "getting size of gif"
- Next in thread: Vinay Sajip: "Re: logging messages in imported modules not showing up"
- Reply: Vinay Sajip: "Re: logging messages in imported modules not showing up"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]