@@ -243,9 +243,13 @@ def restorePreviousLogger(self):
243243 self .logger .addHandler (h )
244244 self .logger .setLevel (self ._previousLevel )
245245
246- def start (self , level ):
247- # Clear log file
246+ def clearLogFile (self ):
248247 open (self .logFile , 'w' ).close ()
248+
249+ def start (self , level ):
250+ # Make sure the log file exists
251+ if not os .path .exists (self .logFile ):
252+ self .clearLogFile ()
249253 self .configureLogger ()
250254 self .logger .propagate = False
251255 self .logger .setLevel (self .textToLevel (level ))
@@ -400,26 +404,18 @@ def updateStatusFromCache(self):
400404
401405 @property
402406 def statusFile (self ):
403- if self .range .blockSize == 0 :
404- return os .path .join (self .node .internalFolder , "status" )
405- else :
406- return os .path .join (self .node .internalFolder ,
407- str (self .index ) + ".status" )
407+ chunkIndex = self .index if self .range .blockSize else 0
408+ return os .path .join (self .node .internalFolder , str (chunkIndex ) + ".status" )
408409
409410 @property
410411 def statisticsFile (self ):
411- if self .range .blockSize == 0 :
412- return os .path .join (self .node .internalFolder , "statistics" )
413- else :
414- return os .path .join (self .node .internalFolder , str (self .index ) + ".statistics" )
412+ chunkIndex = self .index if self .range .blockSize else 0
413+ return os .path .join (self .node .internalFolder , str (chunkIndex ) + ".statistics" )
415414
416415 @property
417416 def logFile (self ):
418- if self .range .blockSize == 0 :
419- return os .path .join (self .node .internalFolder , "log" )
420- else :
421- return os .path .join (self .node .internalFolder ,
422- str (self .index ) + ".log" )
417+ chunkIndex = self .index if self .range .blockSize else 0
418+ return os .path .join (self .node .internalFolder , str (chunkIndex ) + ".log" )
423419
424420 def saveStatusFile (self ):
425421 """
@@ -514,11 +510,14 @@ def process(self, forceCompute=False, inCurrentEnv=False):
514510 self .statThread .start ()
515511
516512 try :
513+ logging .info (f"[Process chunk] Start processing..." )
517514 self .node .nodeDesc .processChunk (self )
518515 # NOTE: this assumes saving the output attributes for each chunk
519516 self .node .saveOutputAttr ()
520517 executionStatus = Status .SUCCESS
521518 except Exception :
519+ # with open(self.logFile, "r") as fo:
520+ # print(f"logfile:<<<{fo.read()}>>>")
522521 self .updateStatusFromCache () # check if the status has been updated by another process
523522 if self ._status .status != Status .STOPPED :
524523 executionStatus = Status .ERROR
@@ -533,7 +532,7 @@ def process(self, forceCompute=False, inCurrentEnv=False):
533532
534533 if executionStatus :
535534 self .upgradeStatusTo (executionStatus )
536- logging .info (f" - elapsed time: { self ._status .elapsedTimeStr } " )
535+ logging .info (f"[Process chunk] elapsed time: { self ._status .elapsedTimeStr } " )
537536 # Ask and wait for the stats thread to stop
538537 self .statThread .stopRequest ()
539538 self .statThread .join ()
@@ -1378,14 +1377,13 @@ def getLogHandlers(self):
13781377
13791378 def prepareLogger (self , iteration = - 1 ):
13801379 # Get file handler path
1381- logFileName = "log"
1382- if iteration != - 1 :
1383- chunk = self .chunks [iteration ]
1384- logFileName = str (chunk .index ) + ".log"
1380+ chunkIndex = self .chunks [iteration ].index if iteration != - 1 else 0
1381+ logFileName = f"{ chunkIndex } .log"
13851382 logFile = os .path .join (self .internalFolder , logFileName )
13861383 # Setup logger
13871384 rootLogger = logging .getLogger ()
13881385 self ._logManager = LogManager (rootLogger , logFile )
1386+ self ._logManager .clearLogFile ()
13891387 self ._logManager .start (self .getNodeLogLevel ())
13901388
13911389 def restoreLogger (self ):
0 commit comments