What's wrong with my logging configuration
Hello, I am using python logging and as of today it stopped working. Here is my program: #!/usr/bin/env python import base64 import getpass import httplib import logging import logging.config import sys import urlparse logging.config.fileConfig('logging.config') logger = logging.getLogger(sys.argv[0]) def main(): from optparse import OptionParser usage = '%prog -u user [options] url' parser = OptionParser(usage=usage) parser.add_option('-u', '--user', help='The user that will be authenticated') (options, args) = parser.parse_args() if len(args) != 1: logger.error('Please provide a url') sys.exit(1) url = args[0] if not options.user: logger.error('Please provide a user') sys.exit(2) password = getpass.getpass('Password: ') if __name__ == '__main__': main() Here is my logging.config: [loggers] keys=root [handlers] keys=console,file [formatters] keys=consolefmt,filefmt [formatter_consolefmt] format=%(name)-12s: %(levelname)-8s %(message)s class=logging.Formatter [formatter_filefmt] format=%(asctime)s %(name)-12s %(levelname)-8s %(message)s datefmt=%d/%m/%Y %H:%M:%S [handler_console] class=StreamHandler level=INFO formatter=consolefmt args=(sys.stdout,) [handler_file] class=FileHandler level=DEBUG formatter=filefmt args=('dav.log', 'a') [logger_root] level=NOTSET handlers=console,file Yesterday, it was working and I have not touched it - logging has been working for months. This morning it stopped working and I was debugging it for half a day and I am clueless. It does not the errors neither on the console nor in the log file. I will appreciate any help! Thank you in advance! Regards Rambius -- http://mail.python.org/mailman/listinfo/python-list
Re: What's wrong with my logging configuration
On Nov 27, 4:07 pm, rambius rambiusparkisan...@gmail.com wrote: Hello, I am using python logging and as of today it stopped working. Here is my program: I forgot to give my environment: $ uname -a Darwin arielmac.lan 10.5.0 Darwin Kernel Version 10.5.0: Fri Nov 5 23:20:39 PDT 2010; root:xnu-1504.9.17~1/RELEASE_I386 i386 $ python -V Python 2.6.6 Regards Rambius -- http://mail.python.org/mailman/listinfo/python-list
Re: What's wrong with my logging configuration
Hello, I was able to reproduce the problem with even a smaller program: #!/usr/bin/env python import logging import logging.config logging.config.fileConfig('logging.config') logger = logging.getLogger('test') def main(): logger.fatal('test1') import optparse logger.fatal('test2') if __name__ == '__main__': main() When I run this program the logger statement after 'import optparse' does not appear. The first logger statement before optparse does appear. Has anyone experienced similar behaviour? Regards Rambius -- http://mail.python.org/mailman/listinfo/python-list
Re: What's wrong with my logging configuration
rambius rambiusparkisan...@gmail.com writes: When I run this program the logger statement after 'import optparse' does not appear. The first logger statement before optparse does appear. Has anyone experienced similar behaviour? I use the same config file (from your first message) and your shorter program, and I see this output: = test: CRITICAL test1 test: CRITICAL test2 = -- \ “I have a large seashell collection, which I keep scattered on | `\the beaches all over the world. Maybe you've seen it.” —Steven | _o__) Wright | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: What's wrong with my logging configuration
Hello Ben, On what environment did you try it? On Nov 27, 5:09 pm, Ben Finney ben+pyt...@benfinney.id.au wrote: rambius rambiusparkisan...@gmail.com writes: When I run this program the logger statement after 'import optparse' does not appear. The first logger statement before optparse does appear. Has anyone experienced similar behaviour? I use the same config file (from your first message) and your shorter program, and I see this output: = test : CRITICAL test1 test : CRITICAL test2 = This is so strange. If I import optparse outside of main() it works. If I import it between the two logging statement, the second one does not appear. Regards Rambius -- http://mail.python.org/mailman/listinfo/python-list
Re: What's wrong with my logging configuration
Hello, I found the culprit. Yesterday I added a file called copy.py. It clashed with the python built-in module copy and caused that nasty error. Regards Rambius -- http://mail.python.org/mailman/listinfo/python-list
Re: What's wrong with my logging configuration
rambius rambiusparkisan...@gmail.com writes: On what environment did you try it? I get the same results with both Python 2 and Python 3 on GNU+Linux: = $ python Python 2.6.6 (r266:84292, Oct 9 2010, 13:53:14) […] $ python3 Python 3.1.3rc1 (r313rc1:86453, Nov 14 2010, 05:49:40) […] = This is so strange. If I import optparse outside of main() it works. If I import it between the two logging statement, the second one does not appear. Troubleshooting questions: Is there a rogue module in your project tree that, by being named the same as one of the standard library modules, shadows that module? Does the same problem behaviour occur if you import some other module in place of ‘optparse’? Can you reduce the content of your ‘logging.config’ and still see the same problem behaviour (i.e. do you really have the minimum complete example yet)? What is the minimal config file that still results in the same behaviour for you? -- \ “Welchen Teil von ‘Gestalt’ verstehen Sie nicht? [What part of | `\‘gestalt’ don't you understand?]” —Karsten M. Self | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: What's wrong with my logging configuration
rambius rambiusparkisan...@gmail.com writes: I found the culprit. Yesterday I added a file called copy.py. It clashed with the python built-in module copy and caused that nasty error. You may be glad to know that newer versions of Python can distinguish absolute imports from relative imports, to address this very problem URL:http://www.python.org/dev/peps/pep-0328/. -- \“I don't accept the currently fashionable assertion that any | `\ view is automatically as worthy of respect as any equal and | _o__) opposite view.” —Douglas Adams | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list