Skip to content

Commit 1ef902e

Browse files
committed
[core] Logging : fix several issues on the log files
1 parent 6d03825 commit 1ef902e

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

meshroom/core/desc/node.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def processChunk(self, chunk):
158158

159159
def executeChunkCommandLine(self, chunk, cmd, env=None):
160160
try:
161-
with open(chunk.logFile, 'w') as logF:
161+
with open(chunk.logFile, 'a') as logF:
162162
chunk.status.commandLine = cmd
163163
chunk.saveStatusFile()
164164
cmdList = shlex.split(cmd)
@@ -190,6 +190,7 @@ def executeChunkCommandLine(self, chunk, cmd, env=None):
190190
stderr=logF,
191191
cwd=chunk.node.internalFolder,
192192
env=env,
193+
text=True,
193194
**platformArgs,
194195
)
195196

meshroom/core/node.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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):

meshroom/core/taskManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def run(self):
6767
stopAndRestart = True
6868
break
6969
else:
70-
logging.error(f"Error on node computation: {exc}.")
70+
logging.error(f"Error on node computation: {exc}")
7171
nodesToRemove, _ = self._manager._graph.dfsOnDiscover(startNodes=[node], reverse=True)
7272
# remove following nodes from the task queue
7373
for n in nodesToRemove[1:]: # exclude current node

tests/test_compute.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ def executeChunks(node, size):
2323
logFiles = {}
2424
for chunkIndex in range(size):
2525
iteration = chunkIndex if size > 1 else -1
26-
logFileName = "log"
27-
if size > 1:
28-
logFileName = f"{chunkIndex}.log"
26+
logFileName = f"{chunkIndex}.log"
2927
logFile = Path(node.internalFolder) / logFileName
3028
logFiles[chunkIndex] = logFile
3129
logFile.touch()

0 commit comments

Comments
 (0)