def __init__(self,path='logs',name='NewLog',debug='off'):
        "Initialize or open logs as log objects are instantiated."
        import sys        
        import os.path
        self.events = []    # list of events written to this log
        self.debug = debug  # flag to activate/deactive debugging messages

        # First try the metadata file
        self.metadatafile = name + '.lmd'
        self.mdf = path + '/' + self.metadatafile
        mfn = os.path.isfile(self.mdf)
        if ( mfn ):
            if ( debug == 'on' ):
                print 'DEBUG: Metadata file',self.metadatafile,'exists.'
            # Since the file exists, get the metadata
            mfn = open(self.mdf,'r')
            self.name = mfn.readline().strip()
            self.path = mfn.readline().strip()
            self.logfile = mfn.readline().strip()
            self.metadatafile = mfn.readline().strip()
            self.checksumfile = mfn.readline().strip()
            self.created = mfn.readline().strip()
            self.modified = mfn.readline().strip()
            mfn.close()
            self.ldf = path + '/' + self.logfile
            self.cdf = path + '/' + self.checksumfile            
        else:
            if ( debug == 'on' ):
                print 'DEBUG: Metadata file',metadatafile,'does not exist.'
            self.name = name
            self.path = path
            self.metadatafile = name + '.lmd'
            self.logfile = name + '.log'
            self.checksumfile = name + '.md5'
            import time
            self.created = time.asctime(time.localtime(time.time()))
            self.mdf = path + '/' + self.metadatafile
            self.ldf = path + '/' + self.logfile
            self.cdf = path + '/' + self.checksumfile            
        
        # Then try the log file
        lfn = os.path.isfile(self.ldf)
        if ( lfn ):
            if ( debug == 'on' ):
                print 'DEBUG: Log file',self.logfile,'exists.'
            lfn = open(self.ldf,'r')
            for line in lfn.readlines():
                self.events.append(line.strip())
            lfn.close()
        else:
            if ( debug == 'on' ):
                print 'DEBUG: Log file',self.logfile,'does not exist.'

        # Finally, try the checksum file
        cfn = os.path.isfile(self.cdf)
        if ( cfn ):
            if ( debug == 'on' ):
                print 'DEBUG: Checksum file',self.checksumfile,'exists.'            
            cfn = open(self.cdf, 'r')
            self.md5 = cfn.read().strip()
            if ( debug == 'on' ):
                print 'DEBUG: MD5 checksum',self.md5,'read from',self.checksumfile
            cfn.close()
        else:
            if ( debug == 'on' ):
                print 'DEBUG: Checksum file',self.checksumfile,'does not exist.'
            pass

        # Once we have read the metadata, verify the integrity of the logfiles.
        self.verify()
Initialize or open logs as log objects are instantiated.
recipes/Python/66452_Logpyl__basic_logfile_objects/recipe-66452.py