logging: AttributeError: 'module' object has no attribute 'getLogger'

Frank GOENNINGER dg1sbg at googlemail.com
Sun May 23 09:46:48 EDT 2010


Hi all:

Being completely new to Python still (just about a week into it now) I
tried to follow the Python 2.6.5 version documemtation aiming at setting
up a logger as follows:

<code>

import logging

global gPIBLogger

class PIBLogger(object):
    '''
    TODO: classdocs
    '''

    def __init__(self, logFileName):
        '''
        Constructor
        '''
        self.logFileName = logFileName
        self.logger = logging.getLogger('PIBLogger')
        self.logger.setLevel(logging.DEBUG)
        handler = logging.handlers.RotatingFileHandler(self.logFileName, 
                                                       maxBytes=1000000,
                                                       backupCount=9)
        self.logger.addHandler(handler)
        gPIBLogger = self.logger
               
        
def main():
    mylogger = PIBLogger('/tmp/pib.log')
    gPIBLogger.debug(' Hi ')
   
if __name__ == "__main__":
    main()

</code>

When trying to execute main() I get:

Traceback (most recent call last):
  File "/.../src/pib/logging.py", line 37, in <module>
    main()
  File "/.../src/pib/logging.py", line 33, in main
    mylogger = PIBLogger('/tmp/pib.log')
  File "/...src/pib/logging.py", line 23, in __init__
    self.logger = logging.getLogger('PIBLogger')
AttributeError: 'module' object has no attribute 'getLogger'

I double checked and yes, getLogger is there. Why is the interpreter
asking for an "attribute" here ? Any hints on what I am doing wrong ?

TIA!

Regards

  Frank



More information about the Python-list mailing list