Skip to content

Commit

Permalink
Making concatLogs work with new context.LOG_DIR (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-science committed Aug 11, 2021
1 parent 5f5483b commit 4e100dd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
7 changes: 5 additions & 2 deletions armi/runLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,17 @@ def close(mpiRank=None):
LOG._restoreStandardStreams()


def concatenateLogs():
def concatenateLogs(logDir=None):
"""
Concatenate the armi run logs and delete them.
Should only ever be called by parent.
"""
if logDir is None:
logDir = context.LOG_DIR

# find all the logging-module-based log files
stdoutFiles = sorted(glob(os.path.join("logs", "*.stdout")))
stdoutFiles = sorted(glob(os.path.join(logDir, "*.stdout")))
if not len(stdoutFiles):
info("No log files found to concatenate.")
return
Expand Down
31 changes: 31 additions & 0 deletions armi/tests/test_runLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from io import StringIO
import logging
import os
from shutil import rmtree
import unittest

from armi import context, runLog
Expand Down Expand Up @@ -192,6 +194,35 @@ def test_setVerbosity(self):
runLog.LOG.setVerbosity(logging.WARNING + 1)
self.assertEqual(runLog.LOG.getVerbosity(), logging.WARNING)

def test_concatenateLogs(self):
"""simple test of the concat logs function"""
# create the log dir
logDir = "test_concatenateLogs"
if os.path.exists(logDir):
rmtree(logDir)
context.createLogDir(0, logDir)

# create as stdout file
stdoutFile = os.path.join(logDir, logDir + ".0.0.stdout")
f = open(stdoutFile, "w")
f.write("hello world\n")
f.close()
self.assertTrue(os.path.exists(stdoutFile))

# create a stderr file
stderrFile = os.path.join(logDir, logDir + ".0.0.stderr")
f = open(stderrFile, "w")
f.write("goodbye cruel world\n")
f.close()
self.assertTrue(os.path.exists(stderrFile))

# concat logs
runLog.concatenateLogs(logDir=logDir)

# verify output
self.assertFalse(os.path.exists(stdoutFile))
self.assertFalse(os.path.exists(stderrFile))


if __name__ == "__main__":
# import sys;sys.argv = ['', 'Test.testName']
Expand Down

0 comments on commit 4e100dd

Please sign in to comment.