What's wrong with my logging configuration

R

rambius

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
 
R

rambius

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
 
R

rambius

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
 
R

rambius

Hello Ben,

On what environment did you try it?

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
 
R

rambius

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top