Пример #1
0
def logToFile(strMessage, strSpecificFileName=""):
    "add a message to the current debug log file"
    global global_strAltools_LogToFile
    global global_mutex_LogToFile
    global global_timeLogToFile_lastLog
    timeNow = time.time()
    rDurationSec = timeNow - global_timeLogToFile_lastLog
    global_timeLogToFile_lastLog = timeNow
    while (global_mutex_LogToFile.testandset() == False):
        time.sleep(0.02)
    if (global_strAltools_LogToFile == None):
        try:
            os.makedirs(pathtools.getCachePath())
        except:
            pass  # often the cases!
        global_strAltools_LogToFile = pathtools.getCachePath(
        ) + getFilenameFromTime() + ".log"
        print("altools.logToFile: logging to '%s'" %
              global_strAltools_LogToFile)

    if (strSpecificFileName == ''):
        strFileName = global_strAltools_LogToFile
    else:
        strFileName = pathtools.getCachePath(
        ) + strSpecificFileName + '_' + naoqitools.getNaoqiStartupTimeStamp(
        ) + ".log"
#    print( "logToFile: logging to %s" % strFileName );
    try:
        file = open(strFileName, "at")
        file.write("%s (%5.2fs): %s\n" %
                   (debug.getHumanTimeStamp(), rDurationSec, strMessage))
    finally:
        if (file):
            file.close()
    global_mutex_LogToFile.unlock()
Пример #2
0
def logToFile( strMessage, strSpecificFileName = "" ):
    "add a message to the current debug log file"
    global global_strAltools_LogToFile;
    global global_mutex_LogToFile;
    global global_timeLogToFile_lastLog;
    timeNow = time.time();
    rDurationSec = timeNow - global_timeLogToFile_lastLog;
    global_timeLogToFile_lastLog = timeNow;
    while( global_mutex_LogToFile.testandset() == False ):
        time.sleep( 0.02 );
    if( global_strAltools_LogToFile == None ):
        try:
            os.makedirs( pathtools.getCachePath() );
        except:
            pass # often the cases!
        global_strAltools_LogToFile = pathtools.getCachePath() + getFilenameFromTime() + ".log";
        print( "altools.logToFile: logging to '%s'" % global_strAltools_LogToFile );
        
    if( strSpecificFileName == '' ):
        strFileName = global_strAltools_LogToFile;
    else:
        strFileName = pathtools.getCachePath() + strSpecificFileName + '_' + naoqitools.getNaoqiStartupTimeStamp() + ".log";
#    print( "logToFile: logging to %s" % strFileName );
    try:
        file = open( strFileName, "at" );
        file.write( "%s (%5.2fs): %s\n" % ( debug.getHumanTimeStamp(), rDurationSec, strMessage ) );
    finally:
        if( file ):
            file.close();
    global_mutex_LogToFile.unlock();
Пример #3
0
 def log( self, strMessage ):
     timeNow = time.time();
     rDurationSec = timeNow - self.logLastTime;
     self.logLastTime = timeNow;
     strTimeStamp = debug.getHumanTimeStamp();
     print( "INF: %s: Xarloader: %s" % ( strTimeStamp,  str( strMessage ) ) );
     while( self.logMutex.testandset() == False ):
         print( "INF: XarLoader: log: locked" );
         time.sleep( 0.02 );
     
     strFilename = pathtools.getCachePath() + "XarLoader.log";
     try:
         os.makedirs( pathtools.getCachePath() );
     except BaseException, err:
         print( "WRN: normal error: err: " + str( err ) );
Пример #4
0
 def dumpAll(self):
     "dump to print all the outputted extracted data"
     print(
         "INF: PersistentMemoryDataManager.dumpAll at %d - humantime: %s" %
         (int(time.time()), debug.getHumanTimeStamp()))
     print("*" * 30)
     while (self.mutexListData.testandset() == False):
         print("PersistentMemoryDataManager.dumpAll: locked")
         time.sleep(0.1)
     for k, v in self.allData.iteritems():
         strOut = "%s " % (k)
         strOut += "(%d val): " % v.getDataHistLength()
         aLastValue = v.getDataHist(3)
         for val in aLastValue:
             strOut += "%s: %s; " % (timeToHuman(val[0]), str(val[1]))
         print(strOut)
     print("*" * 30)
     self.mutexListData.unlock()
Пример #5
0
    def updateData(self, value):
        #        print( "INF: PersistentMemoryData.updateData: %s set to '%s'" % ( self.strName, str( value ) ) );
        while (self.mutex.testandset() == False):
            print("PersistentMemoryData(%s).updateData: locked" % self.strName)
            time.sleep(0.1)
#        self.allValue.append( [ time.time(), typeToString( value ), value ] );
        self.allValue.append([time.time(), value])
        if (len(self.allValue) > 200):
            print(
                "INF: %s: PersistentMemoryData(%s).updateData: reducing history"
                % (debug.getHumanTimeStamp(), self.strName))
            # permet aussi de voir si il n'y a pas des valeurs dans lesquels on poste un peu trop souvent
            self.allValue = self.allValue[-100:]
            # ne garde que les 100 derniers !
        self.lastValue = value
        self.mutex.unlock()
        # locking would be done in the write method
        if (time.time() - self.timeLastSave >
                60):  # save each variables every 60 seconds
            print(
                "INF: PersistentMemoryData(%s).updateData: autosaving data..."
                % self.strName)
            self.writeToFile()
 def dumpAll( self ):
     "dump to print all the outputted extracted data"
     print( "INF: PersistentMemoryDataManager.dumpAll at %d - humantime: %s" % ( int( time.time() ), debug.getHumanTimeStamp() ) );
     print( "*" * 30 );
     while( self.mutexListData.testandset() == False ):
         print( "PersistentMemoryDataManager.dumpAll: locked" );
         time.sleep( 0.1 );            
     for k, v in self.allData.iteritems():
         strOut = "%s " % ( k );
         strOut += "(%d val): " % v.getDataHistLength();
         aLastValue = v.getDataHist( 3 );
         for val in aLastValue:
             strOut += "%s: %s; " % ( timeToHuman( val[0] ), str( val[1] ) );
         print( strOut );
     print( "*" * 30 );
     self.mutexListData.unlock();        
    def updateData( self, value ):
#        print( "INF: PersistentMemoryData.updateData: %s set to '%s'" % ( self.strName, str( value ) ) );
        while( self.mutex.testandset() == False ):
            print( "PersistentMemoryData(%s).updateData: locked" % self.strName );
            time.sleep( 0.1 ); 
#        self.allValue.append( [ time.time(), typeToString( value ), value ] );
        self.allValue.append( [ time.time(), value ] );
        if( len( self.allValue ) > 200 ):
            print( "INF: %s: PersistentMemoryData(%s).updateData: reducing history" % ( debug.getHumanTimeStamp(), self.strName ) ); # permet aussi de voir si il n'y a pas des valeurs dans lesquels on poste un peu trop souvent
            self.allValue = self.allValue[-100:]; # ne garde que les 100 derniers !
        self.lastValue = value;
        self.mutex.unlock();
        # locking would be done in the write method
        if( time.time() - self.timeLastSave > 60 ): # save each variables every 60 seconds
            print( "INF: PersistentMemoryData(%s).updateData: autosaving data..." % self.strName );
            self.writeToFile();