def close(self):
        "Close the log by writing all log and metadata to the proper files.  Also update the checksum file."
        import sys
        import os
        "Write the current version of the log to a file and free the variables used by the log."
        if ( self.debug == 'on' ):            
            print "DEBUG: Closing log", self.name
        # If self.path does not exist, create the directory for the logfiles.
        if ( not os.path.exists(self.path ) ):
            if ( self.debug == 'on' ):
                print 'DEBUG: Directory ',self.path,' does not exist.  I am creating it now.'
            try:                
                os.makedirs(self.path)
                if ( self.debug == 'on' ):
                    print 'DEBUG: Created log file directory',self.path
            except OSERROR:
                print 'ERROR: Could not create log file directory',self.path                
        # Make sure that the metadata file is opened (created) and written.
        import time
        mfn = open(self.mdf, 'w+')
        mfn.write(self.name+'\n')
        mfn.write(self.path+'\n')
        mfn.write(self.logfile+'\n')
        mfn.write(self.metadatafile+'\n')        
        mfn.write(self.checksumfile+'\n')
        mfn.write(self.created+'\n')
        if ( not hasattr(self,'modified') ):
            mfn.write(self.created+'\n')
        else:
            mfn.write(self.modified+'\n')
        mfn.close()

        # Make sure that the log entries are written.
        lfn = open(self.ldf, 'w+')
        for event in self.events:
            lfn.write(event+'\n')
        lfn.close()

        # Create the MD5 checksum from the log file and metadata file
        import md5
        checksum = md5.new()
        mfn = open(self.mdf, 'r')
        for line in mfn.readlines():
            checksum.update(line)
        mfn.close()
        lfn = open(self.ldf, 'r')
        for line in lfn.readlines():
            checksum.update(line)
        lfn.close()
        cs = checksum.hexdigest()        
        if ( self.debug == 'on' ):
            print 'DEBUG: The MD5 digest of the metadata and log files is',cs
        
        # Make sure that the checksum file is opened (created) and written to.
        cfn = open(self.cdf,'w+')        
        cfn.write(cs+'\n')
        cfn.close()
Close the log by writing all log and metadata to the proper files.  Also update the checksum file.
recipes/Python/66452_Logpyl__basic_logfile_objects/recipe-66452.py